I've read a few beginning iPhone game programming books, and they've helped tremendously in my education and advancement in creating a few simple games, but of all the books I've read, there doesn't seem to be anything about creating a Settings Menu or how to change and save settings within a game.

What are some ways that settings can be saved/loaded? Where are these settings saved?

This may seem like a simple, uninteresting question, but I can't find anywhere that has a good explanation on how to go about creating a settings menu and how the data is saved/loaded each time the program ends/starts...

Mind you I'm not really expecting to have code thrown at me, but an explanation on how the structure works and how to wrap my head around the whole concept (though code is pretty ;)). Or even some articles that explain the concept that I could read would be very helpful.


Ignoring the "menu" part of it (it's the same as any other UI element), for iOS games specifically you can use the built-in NSUserDefaults class to store key-value pair of settings.

  • \$\begingroup\$ That was most helpful! Thankyou. I don't know why none of the books I've read have mentioned this before... \$\endgroup\$ – OghmaOsiris Dec 21 '11 at 21:10

Well, you're writing to and reading from temporary variables, and those are in turn written to / read from a file stream when saving and loading, respectively. Your user interface buttons and toggles and other doodats might tie into something like the Command Pattern when hit; but TBH, even that is probably slight overkill for something this simple at its heart. I certainly wouldn't implement Command just for something as simple as settings, but I would use it if it were already part of my UI framework (whether custom or not).

Reading and writing to file streams should be easy enough to find in the iPhone dev docs; alternatively there is probably something like a "temporary local storage" mechanism (this can be found in eg. Chrome, Android, Flash, and HTML5) -- think this is what @Tetrad has mentioned.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.