2013年3月26日 星期二

IBOutlet 到底要放在property 還是ivar

最常見的是把IBOutlet放在property
@interface fooViewController : UIViewController {
   UILabel *fooLabel;
}
@property (nonatomic,weak)IBOutlet UILabel *fooLabel;
@end

但也有人放在ivar
@interface fooViewController : UIViewController {
    IBOutlet UILabel *fooLabel;
}
@property (nonatomic,weak)UILabel *fooLabel;
@end

甚至兩個地方都放的
@interface fooViewController : UIViewController {
    IBOutlet UILabel *fooLabel;
}
@property (nonatomic,weak)IBOutlet UILabel *fooLabel;
@end

這些程式碼都不會出錯,不過我還是想知道到底放在哪裡最好,查到了這一篇講得很清楚。
放在property比較有彈性,且編譯的速度快些,官方文件也是推薦放在property,有興趣的人可以看看。

沒有留言: