好吧!我對聲明變量&實現其屬性的方式感到困惑。是屬性 - 在Objective-C中實現變量
.h文件內容
@interface XYZAppDelegate : NSObject <UIApplicationDelegate> {
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet XYZViewController *viewController;
@end
.m文件內容
#import "XYZAppDelegate.h"
#import "XYZViewController.h"
@implementation XYZAppDelegate
@synthesize window=_window;
@synthesize viewController=_viewController;
我的問題/查詢如下。
- 如果我們放置屬性,我們不需要聲明變量嗎? (使用屬性,我們可以間接聲明變量 - 是這樣嗎?)
- 除此之外,還有哪些其他功能? (在具體編碼中)
- 爲什麼大家堅持在每個屬性訪問器之前使用_? (除了安全威脅?它是否成爲編碼標準?背後的原因是什麼?)
@Abizern - 感謝您的標籤編輯。這會幫助我發佈新內容。 –