Property List vs XML in iPhone - iphone

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.

Related

Is it possible to modify/update the plist file programmatically without replacing it?

In my application
I want to change only some content of the file.
For doing that I am fetching the plist file in dictionary.
Modifying the dictionary and then Re-Writing the whole plist file.
Is it possible to modify the plist file directly or some content of the plist file.
It's not possible to modify a plist file without rewriting the whole file. If your plist file is so big that it takes too long to rewrite the whole thing, you should look at using a SQLite database instead, and perhaps adopting Core Data.
If you are talking about Info.plist or any resource inside your bundle (i.e.: inside MyApp.app folder) the answer is NO.
Files inside your bundle are read-only. So you cannot override them.
If you are talking about other files that could be in Documents or Cached folder then the answer is YES.

Saving, reading, exchanging own file format?

any recommendations for saving four strings into an own file format that is read by the application and can be shared?
In my app, you will be able to enter some text in some boxes and the app shows a view with an background image and those strings. Now, I am already able to save this as a picture, but I actually want to save it to an own file format so that you can save different files that can be modified afterwards as well or even exchanged via email and opened from another iphone with the app.
Now, I wrote the code for accessing the documents folder of the app, as well as saving and deleting. Thing is, i dont know how to store those strings in a file (perhaps in a xml?) and read them easily afterwards from my application.
For the exchanging part, I found that link which would be a nice feature indeed: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
Parsing xml seems not that difficult (never done it before): http://ipad.about.com/od/iPad-App-Dev/a/How-To-Parse-Xml-Files-In-Xcode-Objective-C.htm
If it's only a small bit of infomation then the easiest way to store your data in a file would be using a plist - there's a good tutorial here - http://www.icodeblog.com/2009/02/14/loading-data-from-plist-files/
In addition to the plist, you could also do the following approaches:
1) simplest - open a file in your documents directory, write the 4 strings (using whatever delimiter/end of string marker is useful - carriage return?) and overwrite them each time through. (i.e. it's your file, you can format it how you like)
2) mildly harder - use Apple's NSArchive to pack and unpack the strings.
3) possible overkill - store them directly in a SQLite database
4) major overkill - store them in CoreData.
Of course, the "overkill" options also provide you with extra features which may be of use if your app functionality extends beyond what you've outlined.
By sharing, I would think that simple copy and paste might be enough, but there's also sending it via email, or tripping another app's URL scheme to make it open it and sending the strings as part of the URL. You'd have to know that the other app would be able to interpret your strings as part of the URL, so you might have to write it yourself.
Okay guys I found that very nice method in the NSString documentation:
–writeToFile:atomically:encoding:error:
I think I am gonna separate my strings by /n and save them to a .txt. When I am gonna read the file afterwards, i am getting the string, divide it to substrings. That will do it, I guess.
One last question: Is it possible to replace the content of my file so that I won't need to create a new file every time i want to change something?
Thanks!

iPhone, XML for preload data

I save XML file in Resources folder in xcode. And I parse it when application launches and use it for a default data set. I don't see any problem with this but people are talking about CoreData to handle a default data set. Can I just still use XML file for a default data? what is the disadvantage of using XML for default data set?
I'd say you're fine using an XML file, assuming that the data is small and you're not modifying it a lot. I use a CSV file for a couple of my apps and that's worked fine for me.
With that said, here are better answers to a similar question: Plist vs SQLite vs Core Data for a rss reader type application?

Storing data into an XML under iOS

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/

The best resources file type for iPhone

In my iPhone project, there are a lot of files including: image files, audio files, and text files.
Now the issue is finding the best file type to manage these files. The image files are related with the audio files and the text files.
I need a file that show the relationship of these files.I am currently using txt type, but it seems chaotic. I want to use xls file type but I can't parse the file correctly.
Can anyone help me? Thanks.
Try using a PLIST. They are easy to read (NSDictionary and NSArray can be created from them) and allow associations to be stored. Also, XCode provides native editing support.