- Objective-C中的@property
這里有一篇文章寫的挺好:關于property
- 它是聲明屬性的關鍵字,系統(tǒng)會為該屬性自動創(chuàng)建setter和getter方法(也就是accessor存取器)
- 早期xcode版本中,需要@property和@synthesize配合使用,前者聲明屬性,后者指定合成的方法指向的變量名??蓞⒁?a target="_blank" rel="nofollow">property和synthesize和@property相關
- @synthesize的作用,可參見如下代碼
@interface ViewController ()
@property (nonatomic, copy) NSString *name;
@end
@implementation ViewController {
NSString *baseView;
}
@synthesize name = $name;
-(void)setName:(NSString *)newName {
$name = newName;
// name = newName; // 這樣是不對的,因為synthesize告訴編譯器成員變量叫$name,而不是name;
}
-(void)viewDidLoad {
[super viewDidLoad];
$name = @"";
}
@end
- Block
很多關于block的文章都聲明block是函數(shù),這一點是錯的。首先,Block是對象,這在apple的文檔中有介紹:Working with Blocks
Blocks Programming Topics
- 知乎上有一篇文章:block的本質寫的挺詳細的
- 關于面向對象
這里有一篇文章寫得挺好:OC中面向對象的編程思想