I want to store some user settings like selected image, etc.
How could I do that with an plist?
For basic settings you can use NSUserDefaults. If you need something more complicated (serializing objects) then you should write out and read in a data file.
Related
In my app, I am writing some data, and I want to save it so that I can retrieve it later. How can I save it and where will it be saved?
Please suggest some ideas...
I think you want to store it in a database using Core Data. If you give more specifics I may be able to give a more specific answer.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html
NSUserDefaults would be the obvious suggestion.
Other suggestions would be to write it to a .plist file in the documents directory or use core-data depending on how much you would want to save.
I'm using an NSXMLParser to read data out of a XML, but how can I make my iPhone App storing data into this specific XML.
The case is that I want to create an app to display available dates and one that administrates this dates, whether they are available or not (I'm using an UISwitch to handle this).
Thanks for your answers,
btype.
If you have small amount of data, you can save them in a plist.
See Property List Programming Guide
There's a github project that let's you create XML DOM objects. You can save your XML to your documents folder on the phone.
https://github.com/arashpayan/apxml/
I have tried the various techniques described to serialize a plist I need in order to save the favorites of the user.
Some people also say it is better to save that data into the "user defaults" file.
Which is the better technique and how are they serialized. I have this code
[plistArray writeToFile:filepath atomically: YES];
which adds the object to the array, but cant seem to save the plist edits.
Regards
If you want to save preferences, then the appropriate method is to use the NSUserDefaults mechanism as it will save you a hell of a lot of time and hassle.
However, if you're using a PLIST as a means of persisting data that's stored in say, an NSDictionary, then I think it would be appropriate to use the writeToFile approach.
If you want to save preferences of any kind, just store them in the user defaults dictionary. That's the only correct way – and additionally you make sure, that iTunes will back it up, if the user syncs its phone.
I want to use plist files to hold large data such as image data and other texts. Is this feasible or is it that plist are for holding small string such as needed for settings etc. Will there be any memory issues.
--
Regards,
U'suf
Yes. You can serialize anything into an NSData and put it into a plist.
But a plist is more suitable to store changeable settings, not large binary blobs.
Plists are indeed intended to store relatively small data. As an option you can save image to a file (it may be better solution even if you use database) and store path to the image in plist to load it from there when needed.
I have to save some config parameters with values in iPhone. I need to edit values at app runtime. I see there are two ways to implement this:
1. Use pList file
2. Create new XML file.
What is the best approach to implement this?
Should I use existing Info.pList file?
Thanks
The best solution is probably using a dictionary and saving that to a property list, it's incredibly easy. Do not use the existing Info.plist, you don't want to polute it with your own settings.
Here's a quick exaple on how to save a dictionary to a property list and load it:
http://codersjunto.com/wp/?p=16&cpage=1
An Info.plist file is XML, it is directly readable from a file to a NSDictionary or NSArray. You can also choose the file format as XML or a binary format, the binary format is a lot smaller and can load faster especially over a network.