• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: @dynamic stupidity?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @dynamic stupidity?


  • Subject: Re: @dynamic stupidity?
  • From: Greg Parker <email@hidden>
  • Date: Thu, 25 Feb 2010 19:31:19 -0800

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    email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >@dynamic stupidity? (From: William Squires <email@hidden>)

  • Prev by Date: Re: @dynamic stupidity?
  • Next by Date: Re: [iPhone 3.1] Core Animation that leaves a trial?
  • Previous by thread: Re: @dynamic stupidity?
  • Next by thread: Embedding Custom NSView in NSScroller having strange effect on drawRect calls.
  • Index(es):
    • Date
    • Thread