• 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: My Core Data experiences
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My Core Data experiences


  • Subject: Re: My Core Data experiences
  • From: email@hidden
  • Date: Mon, 22 Jan 2007 16:22:31 +1100

I won't address your first two points - they may be bugs, in which case you should report them at http://bugreporter.apple.com/.

One last thing:
I have been looking for a nice way of dealing with unsupported data types that
are used in many different Entities. For instance NSPoint, NSSIze, NSColor, I
have several Entities that have a location on screen and they all have the same
code for dealing with size and position. I tried making size and position
entities, but that was also a mess and required one-way links.

This is easily resolved - it's what transient properties are for. Any property marked "transient" - the checkbox is there in the model editor in Xcode - will not have a real representation in the store. You implement an NSManagedObject subclass for each entity that has transient properties, and implement the getters & setters to do the appropriate thing. For special value types, the usual behaviour is to have a shadow property on the entity which will hold the actual data, using a CoreData-savvy type (e.g. NSData). Your setter & getter then encode/decode the stored value appropriately.


[Aside: transient properties are also commonly used for calculated values, as read-only attributes, e.g. "fullName" as the concatenation of the real properties "firstName" and "lastName"]

For example, you have a "colour" property, an NSColor. You make that transient. You then create a "colourData" property, of type NSData say. You then implement a getter & setter for the "colour" property which decode and encode, respectively, the NSColor as an NSData, from/ to to the "colourData" property.

There's a lot of finer details you need to observe, so at this point I'll refer you to the following documentation, which explains all this fully, and has sample code:

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/ Articles/cdNSAttributes.html#//apple_ref/doc/uid/TP40001919

Wade Tregaskis

    ICQ: 40056898
    AIM, Yahoo & Skype: wadetregaskis
    MSN: email@hidden
    iChat & email: email@hidden
    Jabber: email@hidden
    Google Talk: email@hidden

    http://homepage.mac.com/wadetregaskis/

-- Sed quis custodiet ipsos custodes?


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >My Core Data experiences (From: Brian Williams <email@hidden>)

  • Prev by Date: My Core Data experiences
  • Next by Date: Re: Relationship between -isEqual and -hash
  • Previous by thread: My Core Data experiences
  • Next by thread: Re: My Core Data experiences
  • Index(es):
    • Date
    • Thread