[MEMO/TIPS] iPhone class / method / instance naming convention

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/

—-

Comments are closed.

Related URL:
  1. Garmin 310XT PK iPhone4 GPS location 精準度
  2. 2011 巴黎馬拉松 – 法國警局
  3. [open source] iPhone , UIImage and PhotosAlbum 上傳一個圖到 simulator 的相簿 PhotosAlbum sample code
  4. 試用 ADIDAS 的 micoach iPhone APP. 跑10K間歇 ( without heart rate monitor)
  5. sample iPhone screen snapshot
  6. [iPhone dev] 今天看到一個精巧的設計 / tableview / iPhone design pattern
  7. 幾個 iPhone dev 的 opensource site
  8. My iPhone 4 / iP 4
  9. @@ 是誰又亂丟箱子在我桌上啊. . .
  10. iPhone icon size / iPhone 人機介面建議守則