2012年11月19日 星期一

Nil, nil, NULL

nil 代表一個類別個體,而個體的指標指向 Empty,而 Nil 則是用來區別所指向的對象是一個類別 Class 而非個體,NULL 則指的是任何指向空值的指標(我們姑且可以想成當作一個數值來使用)。
#define Nil __DARWIN_NULL /* id of Nil class */
#define nil __DARWIN_NULL /* id of Nil instance */

#define __DARWIN_NULL ((void *)0)

#define NULL ((void*)0)

例如想直接透過程式碼來呼叫按紐事件,由於並沒有經由按鈕來觸發,因此必須將輸入的參數設為空值。
- (IBAction)onButton:(id)sender {
NSLog(@"hi");
}

[self onButton:nil];

沒有留言:

張貼留言