开发者

Is this undefined behaviour with Objective-C properties?

I had something like the following code in a project I recently worked on.

@interface DetailsViewController : UIViewContoller {
  UIView* headerView_;
}
@property (nonatomic, retain) UIView* headerView;
@end

@implementation DetailsViewController
@synthesize headerView = undefinedVariableName_;
// ...
@end

undefinedVariableName_ was not defined anywhere in the project and was actually a much less obvious typo.

This compiled perfectly fine (no errors or warnings) and even ran fine on iOS 4. I did not catch this error until the program crashed on 3.1.3 firmware.

Does anyone know if the above behaviour is considered undefined? Is there a way to have the co开发者_StackOverflow中文版mpiler catch such mistakes?


In the modern Objective-C runtime you don’t have to declare the ivars yourself, the compiler will create them for you at the point of @synthesize. If it crashed on the older iOS this version probably doesn’t support the modern runtime yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜