2552/06/06

Objective-c Memory Code

int ran = arc4random()%110;
NSString *moviePath = [bundle pathForResource:@"" ofType:@"mov"];

----

// Conversion of double resolution time in seconds to int is
// safe for times less than half a century or so
int interval = (int)timeDifference;
int seconds = interval % 60;
int minutes = (interval / 60) % 60;
int hours = (interval / (60*60)) % 24;
int days = (interval / (24*60*60));

- (void) calculateDateDifference:(NSDate *) selectedDate {
NSLog(@"calculateDateDifference");
NSDate *dateNow = [[NSDate alloc] init]; // The current date
NSComparisonResult result = [dateNow compare:selectedDate];
switch (result){
case NSOrderedAscending:
NSLog(@"%@ is in future from %@", selectedDate, dateNow);
// This is the only time the method will continue to run, as we dont want to calculate intervals for dates in the past
break;
case NSOrderedDescending:
NSLog(@"%@ is in past from %@", selectedDate, dateNow);
return;
break;
case NSOrderedSame:
NSLog(@"%@ is the same as %@", selectedDate, dateNow);
return;
break;
default:
NSLog(@"erorr dates %@, %@", selectedDate, dateNow);
return;
break;
}
// Calculate the Time Difference
NSTimeInterval timeDifference = [selectedDate timeIntervalSinceDate:dateNow];

double mins = timeDifference / 60;
double hours = mins / 60;
double seconds = timeDifference;
double days = mins / 1440;
}


if ([[NSUserDefaults standardUserDefaults] objectForKey:@"FBUserId"]) {
//Saved session exists;
}
else {
//No Saved session exists;
}

------
NSArray * arrayContainingArguments = [[NSArray alloc] initWithObjects:@"first",@"second",@"third",@"forth",nil];
NSString * downloadedString = @"4 params. 1 = %@, 2 = %@, 3 = %@ and 4 = %@";
NSString * finalString = [NSString stringWithFormat:downloadedString,arrayContainingArguments];
[arrayContainingArguments release];



---
typedef enum {
NSApplicationDirectory = 1,
NSDemoApplicationDirectory,
NSDeveloperApplicationDirectory,
NSAdminApplicationDirectory,
NSLibraryDirectory,
NSDeveloperDirectory,
NSUserDirectory,
NSDocumentationDirectory,
NSDocumentDirectory,
NSCoreServiceDirectory,
NSDesktopDirectory = 12,
NSCachesDirectory = 13,
NSApplicationSupportDirectory = 14,
NSDownloadsDirectory = 15,
NSAllApplicationsDirectory = 100,
NSAllLibrariesDirectory = 101
} NSSearchPathDirectory;

----

NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myfile"];

----

http://www.rawitat.com/category/mac/
http://blog.webscale.co.in/?p=284
Powered By Blogger