xcode4以后关于私有变量的定义问题
2012-07-13 14:06
337 查看
网上有这样一个描述:
Xcode编译错误:Synthesized property 'xxxXXX' must either be named the
same as a compatible ivar or mus
[plain] view
plaincopyprint?
// 2011.07.21
// Xcode 4.0.2
// 64-bit
@interface IvarNameTest : NSObject {
@private
}
@property(nonatomic) NSNumber *number;
@property(nonatomic) float f;
- (void)printValue;
@end
[plain] view
plaincopyprint?
#import "IvarNameTest.h"
@implementation IvarNameTest
@synthesize number = anyIdentifier;
@synthesize f = anyIdentifier2;
- (void)printValue
{
anyIdentifier = [NSNumber numberWithDouble:77.77];
anyIdentifier2 = 7.7f;
NSLog(@"%@, %f", anyIdentifier, anyIdentifier2);
}
@end
说明:
在 64-bit 平台下编译,在 @interface 块中如果没有定义 instance[b] variable,给出了 @property 声明,同时在 @implementation 块中给出了 @synthesize。[/b]
结论:
1)如果是 @synthesize name; 形式,则编译器自动创建的 instance variable 名字就是 name,也就是 @property 声明中的名字;
2)如果是 @synthesize name = XXXX; 形式,则编译器自动创建的 instance variable 的名字就是 XXXX。
我觉得系统就是自动生成了一个用_为前缀的变量名.
在设置为属性的时候,可以明确表示使用这个 "_xx"的变量,如果不写的话,就标识,私有变量也是本身的名字,就是不带_这个前缀了.
Xcode编译错误:Synthesized property 'xxxXXX' must either be named the
same as a compatible ivar or mus
[plain] view
plaincopyprint?
// 2011.07.21
// Xcode 4.0.2
// 64-bit
@interface IvarNameTest : NSObject {
@private
}
@property(nonatomic) NSNumber *number;
@property(nonatomic) float f;
- (void)printValue;
@end
[plain] view
plaincopyprint?
#import "IvarNameTest.h"
@implementation IvarNameTest
@synthesize number = anyIdentifier;
@synthesize f = anyIdentifier2;
- (void)printValue
{
anyIdentifier = [NSNumber numberWithDouble:77.77];
anyIdentifier2 = 7.7f;
NSLog(@"%@, %f", anyIdentifier, anyIdentifier2);
}
@end
说明:
在 64-bit 平台下编译,在 @interface 块中如果没有定义 instance[b] variable,给出了 @property 声明,同时在 @implementation 块中给出了 @synthesize。[/b]
结论:
1)如果是 @synthesize name; 形式,则编译器自动创建的 instance variable 名字就是 name,也就是 @property 声明中的名字;
2)如果是 @synthesize name = XXXX; 形式,则编译器自动创建的 instance variable 的名字就是 XXXX。
我觉得系统就是自动生成了一个用_为前缀的变量名.
在设置为属性的时候,可以明确表示使用这个 "_xx"的变量,如果不写的话,就标识,私有变量也是本身的名字,就是不带_这个前缀了.
相关文章推荐
- 关于ucos全局变量定义的问题
- 关于Python函数定义全局变量执行弹出SyntaxWarning的问题
- 关于as中变量定义中SCOPE的问题
- c中switch case 中关于变量定义问题
- 关于头文件定义全局变量等问题
- 关于头文件定义全局变量等问题
- 关于C语言BSS段问题以及变量定义的解答
- pl/sql 关于变量定义的问题
- 转载:关于C语言头文件的应用问题,主要还是关于全局变量的定义和声明问题
- pl/sql 关于变量定义的问题
- 关于keil多c文件工程中bit变量的声明定义问题
- c++中switch case 中关于变量定义问题
- 关于头文件定义全局变量等问题
- 关于头文件变量重复定义问题怎么解决(thinkvd开发日志)
- 关于私有变量的调用问题
- 关于“在C语言中只能在函数前面定义变量”的问题
- 静态成员变量初始化问题。关于 error LNK2005 static int:已经在***.obj中定义
- 关于方法内定义的类引用局部变量需要将变量设置final的问题
- 关于Action里面定义的变量问题
- 关于 私有变量的访问问题【 java python]