iOS实例变量声明
我想知道像这样声明实例变量有什么区别:iOS实例变量声明,ios,objective-c,declaration,ivar,Ios,Objective C,Declaration,Ivar,我想知道像这样声明实例变量有什么区别: // inside the implementation file (.m) @interface MyCustomObject() { id _myIvar; } @end @implementation MyCustomObject ... @end // inside the implementation file (.m) @implementation MyCustomObject{ id _myIvar
// inside the implementation file (.m)
@interface MyCustomObject()
{
id _myIvar;
}
@end
@implementation MyCustomObject
...
@end
// inside the implementation file (.m)
@implementation MyCustomObject{
id _myIvar;
}
...
@end
就像这样:
// inside the implementation file (.m)
@interface MyCustomObject()
{
id _myIvar;
}
@end
@implementation MyCustomObject
...
@end
// inside the implementation file (.m)
@implementation MyCustomObject{
id _myIvar;
}
...
@end
从使用的角度来看,没有区别
从《宣言》的角度来看,第一类是: 因此,如果在头文件中有一个同名的变量,那么实现文件将看到这个变量,但是导入该头文件的其他类将看到另一个变量 这种机制对于将不同的属性或属性分配给同一个var非常有用,但是要将公开的var与私有的内部var区分开来