class : 大寫開頭
method / instance : 小寫
Property List / SQLite 寫法 sample
類似 printf 的寫法
NSString *debugMsg = [NSString stringWithFormat:@"Process %d", 1];
取亂數
定義:
#define RANDOM_SEED() srandom(time(NULL))
#define RANDOM_INT(__MIN__, __MAX__) ((__MIN__) + random() % ((__MAX__+1) - (__MIN__)))
// --- 這樣用
NSLog(@"%d" , RANDOM_INT(0,9) );
取 unixtime :
NSDate *past = [NSDate date];
NSTimeInterval oldTime = [past timeIntervalSinceDate:[NSDate dateWithNaturalLanguageString:@"01/01/1970"]];
NSString *unixTime = [[NSString alloc] initWithFormat:@"%0.0f", oldTime];
NSLog(@"%@" , unixTime);
印出 debug message / popup alert 的寫法:
// ---
-(void) printdebug:(id)msg {
NSLog(@"%@", msg);
}
// ---
-(void) displayAlertMessage:(id)msg {
// Display AlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"___Alert___" message:msg
delegate:self cancelButtonTitle:@"Close" otherButtonTitles: nil];
[alert show];
[alert release];
}
Objective-C 奇怪的 null detect!
if ( (NSNull *)[item objectForKey:@"nick"]==[NSNull null] ) {
// FOR GUEST DATA
cell.textLabel.text = @"Guest";
} else {
// FOR MEMBER DATA
cell.textLabel.text = [item objectForKey:@"nick"];
}
ASYNC network 寫法:
http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api/
—-