问题
I'm working on a puzzle game, the game engine holds a complex hierarchy of objects, from game actors to vectors to transition animations. Depending on the game state, they might add up from 10 to 1000 (in extreme cases). I've been delaying the moment until I'd have to work on the saving and loading of all that mess, as I have no experience on this, but now the moment I was fearing is about to arrive.
Is it a good idea to use NSKeyedArchiver for this? Its concept seems powerful. That way I could rebuild the objects states, but does that include the pointers between saved objects? And how does it behave performance-wise? Will the system have time to save all these objects on disk on app termination?
回答1:
NSKeyedArchiver is quite powerful, but it will not let you retain linkages between objects (unless you add them yourself post-unarchiving). If you can/need to store your entire data set atomically, then NSKeyedArchiver is probably the way to go, but there will be some 're-hydration' involved on your part if there's anything more complex then parent-child relationships.
We have a complex hierarchy of data objects, we store them out to an SQLite database, and re-hook them up when we extract them.
回答2:
I went for NSKeyedArchiver, which does maintain references between objects. See here: Easy way to archive interlinked objects
来源:https://stackoverflow.com/questions/307681/best-way-to-save-load-iphone-game-data