I have a .plist filled with data that ships with my app.
It’s basically an array of dictionaries with other arrays/dictionaries in it.
The values I take from this array and use in my app may be a name, so “Computer”.
I’m adding a feature to let the user create their own item, instead of choosing from what is loading from the array. But should I then save this item into the same .plist, or create a separate .plist for each user?
Then, how do I pull info from both the standard .plist and the user created .plist and load them into one tableView?
If you’re writing for iOS, you can’t really save to same plist file because you can’t write to the application bundle.
One thing you could do is save a copy of that plist to the application’s Documents folder, and then modify that same plist, that way all your data is unified in a single file.
Or you can always load the original plist from the application bundle, make a mutable copy of the
NSArray, load an additional plist from the Documents folder with the user’s objects, and append them to theNSMutableArrayby callingaddObjectsFromArray.Or you can even keep them in separate
NSArraybut display them in the table view as one by returning[originalDataArray count] + [userDataArray count]from thetableView:numberOfRowsInSection:method of your table view data source, and of course use the appropriate data in thetableView:cellForRowAtIndexPath:method.EDIT:
About saving the user data, you don’t necessarily have to worry about writing a plist.
The
NSArrayconforms to theNSCodingprotocol, and so doNSDictionary, which means you can easily save it and load it using something like theNSKeyedArchiverclass.Here’s an example of something I had in an old project of mine, where I had a
NSMutableArraythat held some user generated data, and I saved it and loaded it withNSKeyedArchiver(simplified to only show the relevant code, and was done over a year ago when I was just starting with ios, so might not be the best possible way of doing it):