On Feb 25, 2010, at 7:10 PM, William Squires wrote: > What exactly does @dynamic do? Specifically, in the context of a Core Data > managed-object? Here's what I do understand: > > 1) You create an 'entity' in the .xcdatamodel file > 2) You ask Xcode to create the class files for you > 3) The .m file contains @dynamic instead of @synthesize for each of the > entity's 'attributes' (which now correspond to instance variables in a class > derived from NSManagedObject) > > Here's what I don't understand: > > Why doesn't it just @synthesize the accessors? What would happen if I > replaced the @dynamic with @synthesize? Would it blow up, or just have weird > performance issues?
The accessors needed by Core Data and NSManagedObject are complicated, requiring things like change notifications. You can write your own accessor methods by hand, including the necessary complications. Or you can let Core Data add the methods at runtime for you. @dynamic tells the compiler that you have declared properties, but the method implementations for those properties will be provided by someone else. In the NSManagedObject case, "someone else" is equal to "Core Data at runtime". @synthesize tells the compiler to emit method implementations for your properties. @synthesize does not work with NSManagedObject because the implementations it generates don't include the extra features needed by Core Data. The Core Data documentation includes more details about NSManagedObject accessors, with examples of @dynamic and hand-written implementations: http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html -- Greg Parker gpar...@apple.com Runtime Wrangler _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com