iOS defaults db
I am off to making a tower defense game, and will have about 40-50 towers and about 20 enemies on screen. Those objects wil开发者_如何学运维l have a few properties each, like hp, damage, speed etc.
What is the limit of the defaults db? I don't feel like writing SQL queries for simply saving the state of my game..
NSUserDefaults provides a way to store basic information. The only thing is the classes you intend to store must be NSCoding-compliant and wrapped in NSData. This is because NSUserDefaults requires its content to be 100% PLIST-compliant types (NSDictionary, NSArray, NSData, NSString, NSNumber, NSValue...).
Brad is correct, however: easiest (and best practice) to dump this in a data file.
Sure - you can use NSUserDefaults to store as much info as you want. You could also look into Core Data as well (might scale a lot better in the future).
Your best bet is to look into NSCoder methods for saving entire class/properties.
There are a dozen NSCoder tutorials you can check out:
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=nscoder+tutorial
It might be easier with something like this to take the data and just read/write it to a file - rather than dealing with something like the defaults. You could basically have a static data structure that you convert to an NSData with - and write it to storage with NSFileManager's createFileAtPath:contents:attributes: in one whack!
精彩评论