原先以@property宣告的變數,必須在實作時,實作出getter & setter或是以@synthesize讓compiler自動補上。
但在Xcode 4.4 有了Atuomatic Property Synthesis功能之後, 原先以@property宣告的變數,將由compiler自動補上@synthesize動作
例如:
#!objective-c
// in BatMan.h
#import
@interface BatMan : NSObject
@property (strong, nonatomic) NSString *name;
@end
#!objective-c
// in BatMan.m
#import "BatMan.h"
@implementation BatMan
// @synthesize name; // Before Xcode 4.4
/* With APS, the compiler will auto generate the following getter and setter.
- (NSString *)name
{
return _name;
}
- (void)setName: (NSString *)name
{
_name = name;
}
*/
@end
這篇文章其實是從自己的GitHub 轉貼過來的,
但沒想到,居然可以將整個Wiki 風格給貼過來!!!
真是有趣~
沒有留言:
張貼留言