- NULL 是使用 nil ,且 nil 是能夠傳遞訊息的,例: [nil Message];
- BOOL 在 Object-C 型態為 YES 跟 NO;
- 盡量使用 #improt 不使用 #include
- 使用 NS 為型別的前輟名,例: NSString, NSNumber
- ARC(Automatic Reference Counting) 支援 iOS 4.0 以上SDK
- 在方法中開頭為 「+」號的是靜態方法,「-」號的是實例方法,例: +(void) helloWold; -(NSString) helloWorld;
- .h 為標頭檔,做為宣告屬性及方法使用, .m 為Objective-C檔,做為實際編寫屬性值及方法內容使用。
- 屬性宣告需要在 .h檔的 @interface { ........ } 之中
- 方法宣告需要在 .h檔的 @interface {} .............. @end 之中
- 方法實作需要在 .m檔的 @implementation {} ......................... @end 之中
- 如宣告屬性需要在 .h檔加入 @property ,並且在 .m檔加入 @synthesize,例:
.h > @property (nonatomic, retain) NSString userName;
.m > @synthesize userName = _userName;
使用 self.userName = @"Arvin"; 方式操作 - 如宣告型別為 NSInteger, CGFloat, int, float, double, char 時,@property 需使用 assign
- retain:保留, release:釋放, alloc(Allocation):分配, dealloc(Destruction):銷毀
- 呼叫方法的方式為
.h > -(void) MethodName;
.m > -(void) MethodName { ....... };
呼叫使用 [self MethodName]; - 呼叫帶參數方法為
.h > -(void) MethodName:(NSString*) arg1 withAge:(int) arg2;
.m > -(void) MethodName:(NSString*) arg1 withAge:(int) arg2 { ......... };
呼叫使用 [self MethodName: @"Arvin" withAge: 27]; - Sleep 的方法為 [NSThread sleepForTimeInterval:1];
- #pragma mark - 可以標註區塊,例如: #pragma mark - 更新方法
資料來源:
沒有留言:
張貼留言