Property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects

今天在声明一个类属性的时候遇到了这样一个错误 “ Property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects” 。我类声明文件 ( .h) 如下:

1
2
3
@interface MyNoteViewController:UIViewController
@property (nonatomic, strong) NewNoteViewController *newNoteViewController;
@end

然后在我的执行文件 (.m) 中如下的地方就会出现这个错误:

1
@synthesize newNoteViewController = _newNoteViewController;

找了半天,看了半天也没有发现到底是那的错误,最后在StackOverFlow上面找到了答案,原来在iOS5中,如果你的项目支持ARC的话,那么你的property的名字不能以new开头。具体的原因在这里 http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html

To allow interoperation with manual retain-release code, ARC imposes some constraints on method and variable naming:
You cannot give a property a name that begins with new.
悲催的bug,要谨记啊,一定要尽量的避免使用new这样的关键字作为变量的开头,说不定哪天就出现了问题。