E.M.
E.M.

Reputation: 4547

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 compiler catch such mistakes?

Upvotes: 1

Views: 118

Answers (1)

anon
anon

Reputation:

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.

Upvotes: 1

Related Questions