I have 9×9 matrix array as follow. I want to store it in my iPhone app locally as game parameters.
int str2Darray[9][9] = {
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
};
Is it possible to store above array in .plist file? Please suggest any other way also, if any.
You most certainly don’t want to store that in your Info.plist. As the same already says, that’s for information about your app, not data storage. Instead put a separate file in your app’s resources and save your data in there.
You could transform your data into a 2D array of
NSNumbersinNSArraysand write thatNSArrayinto a separate plist file, but that’s a lot of overhead.Instead, if you already know that the array’s size will always be 9×9, I recommend passing the array to an
NSDataobject and save that into a file.If this array represents the state of your game at any point and you want to save it, so that the user can continue when he returns to your app, then you should save it to your documents folder.
If it represents level data, or the start configuration of your game that you want to ship with your game, then I recommend starting a temporary simple second project. Execute it once, grab the saved file and put it into your projects resources.
You can then access it at this path: