Re: Swift Enums and CoreData
Re: Swift Enums and CoreData
- Subject: Re: Swift Enums and CoreData
- From: Rick Aurbach <email@hidden>
- Date: Tue, 07 Jul 2015 00:48:36 -0400
- Acceptlanguage: en-US
- Thread-topic: Swift Enums and CoreData
Ah, I see what you’re getting at. This is interesting.
Previously when I’ve wanted to implement things like this I’ve used Transformable attributes, which provide an automatic packing/unpacking feature using a packing/unpacking class that I specify in the data model. It is necessary to be careful how one handles making sure the object is marked dirty appropriately, but that’s not too hard.
In my case, I’m thinking of using this approach to map a data BLOB (stored as an NSDate object in CD) to a mutable dictionary. The dictionary keys would depend on which enumeration value is associated with the event.
Cheers,
Rick
On Jul 6, 2015, at 6:29 PM, Quincey Morris <email@hidden<mailto:email@hidden>> wrote:
On Jul 6, 2015, at 16:21 , Rick Aurbach <email@hidden<mailto:email@hidden>> wrote:
Are you suggesting that we implement a custom fetched property
No, I’m thinking of this:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html#//apple_ref/doc/uid/TP40001919-SW13
under the heading “Scalar Value”, but some of the details are here:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/uid/TP40002154-SW1
The idea is that you create non-primitive accessors that have a type that’s not known to Core Data. You back it with a Core Data property, using any convenient mechanism. Optionally, you can have an instance variable that caches the non-CD value, or you can just convert it back and forth on the fly.
Note that you can, of course, back your customized property with multiple CD properties, or with a CD property whose value themselves have sub-properties.
_______________________________________________
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