Reputation: 1965
What other ways than NSUserDefaults
are there to save and get back Custom Objects? For me, NSUserDefaults
has become too much of a hassle (it's not saving correctly), so I'm looking for another way to save data that will work. (I've already posted my problems, and I really just want to look for other ways to save data)
EDIT: I also need to be able to save things like UIIMages and UIButtons.
Upvotes: 0
Views: 269
Reputation: 14834
To store custom objects, you need to make sure your custom objects implemented NSCoding protocol. Here is Apple's doc on NSCoding. . If you need a tutorial on how to implement NSCoding protocol, check out this site. To save UIImage to a file, you can convert the image to NSData and then using NSData's writeToFile method to write to a file. There are numerous examples on how to do the last part on SO. Here is one.
Upvotes: 0
Reputation: 42598
UIImages should be saved by creating a PNG or JPEG representation, then writing that NSData block out as you see fit. See UIImagePNGRepresentation.
UIButtons should be serialized/deserialized using the NSCoding protocol. Archives can take care of this for you.
NSData and UIButtons both support NSCoding, so I would recommend archiving instead of NSUserDefaults. See NSCoding for the beginning of that rabbit hole.
Upvotes: 1
Reputation: 6166
You cans use plist or coreData.As you used NSUserDefaults , that means data is quite small so plist will be a good idea.Both are apple's so quite effiecient .If data gets really large you can use sqlite.
Upvotes: 0
Reputation: 11839
text
file or plist
file.SQLLite
to save data.Other than this if you are using server driven application, then you can save your data on server and get back when you need that.
Upvotes: 1