我是新來的Objective-C,和我看到一些像打開下面來源代碼:差異私有變量和財產類擴展聲明
DetailedViewController.m:
@interface DetailedViewController()
@property(nonatomic, strong) UITableView *dynamicTable;
@end
@implementation DetailedViewControll
-(void)viewDidLoad
{
[super viewDidLoad];
self.dynamicTable=[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
//configure dynamicTable
}
@end
如果我宣佈dynamicTable變量,如下使用它:
@interface DetailedViewController()
{
// private tableview variable
UITableView *dynamicTable;
}
@end
@implementation DetailedViewControll
-(void)viewDidLoad
{
[super viewDidLoad];
dynamicTable=[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
//configure dynamicTable
}
@end
我想用dynamicTable變量的以上兩種方式都是平等的,我說得對不對?
如果沒有,是否使用屬性比使用私有變量更好?
@Krumelur不,這是不正確的。 – Fogmeister
以上兩種方式都是.m文件,而不是.h文件,所以我希望它是私人的。 –
Josh Caswell:你的鏈接問題不是重複的。它涵蓋了一個不同的主題:使用顯式變量支持屬性是否是個好主意。這個問題是關於變量與財產本身(儘管我確信這裏有重複的問題)。 – DarkDust