Greg
Greg

Reputation: 34798

how can I store DayOfWeek and a Time in CoreData?

How best could I store day-of-week and a time within core data? For example:

I can represent this within Objective-C using NSDateComponents however this type isn't listed in the core data attributes type drop down list. For that matter these doesn't seem to be an NSTime type either in Objective-C or core data. Options that come to mind:

Upvotes: 0

Views: 542

Answers (1)

Nick Weaver
Nick Weaver

Reputation: 47241

If the classes representing your data conform to the NSCoding protocol you can make use of Transformable Attributes. A short quote from Apple's chapter Non-Standard Persistent Attributes pf Core Data Programming Guide:

The idea behind transformable attributes is that you access an attribute as a non-standard type, but behind the scenes Core Data uses an instance of NSValueTransformer to convert the attribute to and from an instance of NSData. Core Data then stores the data instance to the persistent store.

NSDateComponent does conform to the protocol :)

Upvotes: 3

Related Questions