darksky
darksky

Reputation: 21049

Data Persistence - Singleton Class

I have a singleton class that stores three NSMutableArrays. Each array stores about 4 - 5 items of a custom object I called Program. How can I store those beyond the current application instance?

Should I go with Core Data? I think this is too simple for Core Data. I am already using Core Data for more complex storage in my app. Is there something like NSUserDefaults where I will be able to store those arrays with custom objects and retrieve them easily?

Thanks

Upvotes: 0

Views: 221

Answers (1)

SVD
SVD

Reputation: 4753

NSUserDefaults can't store arbitrary objects, but only instances of NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. You can, however, convert your object into one of those - e.g. by using NSKeyedArchiver:

+ (NSData *)archivedDataWithRootObject:(id)rootObject 

(just implement the two NSCoding protocol methods in your Program class).

Upvotes: 2

Related Questions