Automatic @property synthesize not working on NSManagedObject subclass
Asked Answered
S

1

25

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

Saundra answered 20/9, 2012 at 10:34 Comment(5)
I've got the exact same problem. It seems it's not working on nsmanagedobject.Billingsgate
Me too! Anyone found a fix yet?Radiancy
@Billingsgate , i didn't recognize this at first but you are right, it seems to just don't work on NSManagedObject and subclasses thereof.Saundra
The best workaround is just to synthesize the properties.Billingsgate
Yes. i've contacted apples dev support though and sent them one of my projects. If they can help i'll post their answer here.Saundra
W
36

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.

Wroughtup answered 22/9, 2012 at 14:33 Comment(2)
I've received an answer from apple's dev-support, it's basically what you said: "DNAnnotation is a descendant of NSManagedObject which imposes a restriction upon the auto synthesis of properties. NSManagedObject requires that all properties defined in subclasses of it be explicitly synthesized by the programmer. You will need to add an appropriate (at)synthesize or (at)dynamic statement for the mapAnnotation property."Saundra
It also happens with CMMotionManager, which doesn't have any NS_REQUIRES_PROPERTY_DEFINITIONS in its header file...Heartstrings

© 2022 - 2024 — McMap. All rights reserved.