when starting to use NSUserDefaults for a custom classes is this time to move to Core Data?
When starting to use NSUserDefaults for a custom classes, with multiple levels, is this time to move to Core Data?
Background:
- I did start off using NSUserDefaults for my application data, which was basic 3 levels (see below for a rough example)
- I then wanted to have more readability/typing when using the structure so have started to create custom classes for the data
- I'm now realizing these custom classes will need to implement initWithCoder and encodeWithCoder methods
So given the above I'm really wondering whether I'd be better off going to Core Data here. Don't you conceptually here get to define the structure in XCode then have access saving/loading the data directly into the cla开发者_如何学JAVAsses XCode creates for you?
Rough examples of structure:
- Items (NSMutableArray)
- aString: NSString
- aString2: NSString
- aDate: NSDate
- aDate2: NSDate
- aBool: BOOL
- aTI1: NSTimeInterval
- aTI2: NSTimeInterval
- Keywords (NSMutableArray)
- keyword: NSString
- keyword: NSString
Core Data or property lists or straight up object archival, yes. As soon as you have any kind of data beyond very simple key/value pairs, you need to think about your model layer.
Convenient though it is, user defaults -- as the name implies -- just isn't a place to persist user data! It is for configuration, preferences, etc...
精彩评论