tags:

views:

25

answers:

2

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

+1  A: 

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.

unset
+1  A: 

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.

djhworld
Thanks, I am trying the writeToFile method and it doesnt persist the data. it is there in the simulator when the app relaunches, but it is gone when the simulator restarts?
alJaree
I'm not too familiar with the iPhone SDK but I'm taking a wild guess that when you build and deploy to the simulator - it overwrites the package that is on there with your newly built application. To see if your persistence mechanism is working you should deploy your app, run it (thus running your persistence code) and clicking the home button at the bottom of the simulator. Your persisted data should be there when you open the app up again
djhworld
"deploy your app, run it" - does that mean build and go? But yeah, if I run my app and hit the home button, then upon reopening the app, the data is still there. :)
alJaree
Yeah I guess it means that, whatever you have to do to get the app 'sent' to the simulator anyway.
djhworld