Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic @property synthesize not working on NSManagedObject subclass

After updating to the newest Version of Xcode 4.5 for iOS6 last night, i get Warnings and Errors like this

Property 'mapAnnotation' requires method 'mapAnnotation' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

because of missing @synthesize Statements, and even Errors about unknown iVars if i use them.

The thing is, i thought it was not necessary to write these @synthesize statements since the last Xcode Update to 4.5 that came out with Mountain Lion, AND all my projects worked without them before i've updated Xcode last night (i've deleted a whole bunch of @synthesize statements from my files back then) It's even still in the Release-Notes:

• Objective-C @synthesize command is generated by default when using properties.

So i'm confused, am i missing a new Project-Setting that turns automatic @synthesize generation on?

But it's not even working when i create a new Project and try it

like image 448
MeXx Avatar asked Sep 20 '12 10:09

MeXx


1 Answers

I faced the same problem and found the reason and the solution.

If you look at the header file of NSManagedObject in iOS 6 SDK, you'll see "NS_REQUIRES_PROPERTY_DEFINITIONS" which forces classes to specify @dynamic or @synthesize for properties.

(You can see the NS_REQUIRES_PROPERTY_DEFINITIONS in the API diff between iOS 5.1 and iOS 6.0.)

This is because the compiler has to know if you want a property to be dynamic or synthesized especially in the implementation of a subclass of NSManagedObject class.

I could solve this problem simply by adding the @synthesize lines explicitly for the properties other than @dynamic in NSManagedObject subclasses.

like image 52
Taka Avatar answered Nov 05 '22 23:11

Taka