Loading Data Files on iPhone?
What is the best way to load static data files containing game level maps on the iPhone? I have seen some use XML files, but that seems like overkill in my situation as the data files merely determine the layout of the game's level, ie where obstructions will go. Also, what project directory should they be stored in?
Thanks in advance!
If your files are really static, then you'll want to store them in your application bundle (just add them to your project; Xcode will copy them to the .app bundle when it builds your application). If you need to modify and re-save them, probably ~/Documents is your best bet.
Marc is correct, an NSDictionary is the simplest way to go, especially for smaller files. If you've got a LOT of data, this could get slow when loading in, but that means 10s, or 100s of kilobytes. Also think about converting your dictionary to binary format when you're happy with its contents, as that will load much faster on the device.
I would put the data in a property list file you can load into a dictionary.
I would strongly suggest using the existing SQLite functionality that is part of the standard API.
I have found it to be the easiest way to include data during an installation as well as store user generated data.
If you need an example of how to do this check out http://tetontech.wordpress.com/2008/06/28/iphone-objective-c-sqlite-development/