简体   繁体   中英

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 classes 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM