How best could I store day-of-week and a time within core data? For example:
- Mon 4.05am
- Wed 8.10pm
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:
- store as string and then have to parse (e.g. “Mon 5.00pm”) however that doesn’t sound ideal
- store as (a) NSInteger for day-of-week, and (b) NSDate for time, and only use the time portion when accessing later?
- other better ideas?
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:
NSDateComponent does conform to the protocol 🙂