2011-11-17 49 views
1

我在iOS上跟隨Apple的「Hello」教程,我想知道爲什麼需要聲明「userName」變量(稍後會在代碼中進行訪問)。它不是由合成語句生成的嗎?IOS sythesize - 什麼時候聲明一個內部變量?

@interface HelloWorldViewController : UIViewController { 
    NSString *userName; 
} 

- (IBAction)changeGreeting:(id)sender; 
@property (weak, nonatomic) IBOutlet UILabel *label; 
@property (weak, nonatomic) IBOutlet UITextField *testField; 
@property (nonatomic, copy) NSString *userName; 

下面是合成的實現:

@synthesize label=_label; 
@synthesize testField=_testField; 
@synthesize userName=_userName; 

回答

1

它不是由酒店/合成總是產生。這是對Objective-C的一個相對較新的補充。這個教程可能是在這種情況發生之前編寫的。

+0

不是 - 它是全新的。它使用XCode 4.2,故事板,拖放代碼生成等。 –

+0

他們可能會重複使用以前教程中的代碼。 – Randall

相關問題