Is it possible to load/save the whole structure of plist in setting bundle using NSUserDefaults - iphone

I know it can use NSDictionary to load and save whole plist file on iphone document directory with its structure.
But is it possible to load/save the whole structure of plist in setting bundle using NSUserDefaults?

I'm pretty sure the following works for saving arrays in NSUserDefaults so it should work fine for a NSDictionary
[[NSUserDefaults standardUserDefaults] setObject:dictionary forKey:#"Dictionary"];
Hope that helps

Related

How to save highscore and load highscore in a cocos2d iphone game

I have made my first iPhone game and i have it in the beta testing stage, but then i realised i am missing high score. I don't know how to add high score into the game and if anyone could help me it would be greatly appreciated, also could you tell me if it goes in the game scenes .m or .h file and where to declare it cheers.
Also i have tried to do this before and failed.
The best way to achieve this is using game center. It's very simple to integrate.
You could:
Use NSUserDefaults
Use plists
Use CoreData
If it is just a numerical value you want to store, defaults and plist are fine. But in case you want to store high scores, names, times, and/or scores of many/other users, et cetera, I would suggest using CoreData.
To save some data :
[[NSUserDefaults standardUserDefaults]setObject:yourNumber forKey:#"HighScore"];
to read it :
int high=[[NSUserDefaults standardUserDefaults]objectForKey:#"HighScore"];
This is objective c, cocos2d does not have some special way to save the data for you .
You better not use the game center only, but keep some copy at the user defaults .
First way: look at the plist this is the best way to store highscore load whatever your highScore into Plist and then retrieve that highscore from plist whenever you need. Look at this tutorial: Look at this tutorial
Second way is to store your highscore into NSUSerDefault and retrieve when you want.
NSuserDefault only vanish when you delete the app from simulator or device. So this is also solution for you..
Look at this
Save data to default:
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setObject:highScore forKey:#"High Score"];
[def synchronize];

WriteToFile Problem in iPhone with Model Class

I have problem in WriteToFile in iPhone LazyLoading application.
One of my project i am using lazyloading in that project i want to cache all data in to document directory
in that entry NSArray object containing AppRecored model class objects so i want to write entry NSArray in to Document Directory.
I know the WriteToFile is write the plist file so all the object are NSDictionary, NSArray, NSString and NSNumber but is there any chance to store that array containing model class.
Please let me know your comments...
Thanks in advance.
I got the answer for NSKeyedArchiver & NSKeyedUnArchiver...

Saving and retrieving data from NSMutablearray

I have a NSMutableArray holding string data.
I want to save my data.
When i turn off the application and relaunch the application my saved data need to be presented.
And I need to know where the file saved.
This question is basically the same as yours: Saving a NSArray
Another option is to save it in NSUserDefaults.

Reading pList through NSUserDefaults

If i have values saved in pList Files. Now can i retrieve them using
[NSUserDefaults standardUserDefaults] stringForKey:#"Field_Name"]
Taimur
The NSUserDefaults are not the same as your plist files. I am assuming that you are trying to use default settings in your app? Here is what you do
On first launch, read all the values from the plist. You can see this by looking for a flag in NSUserDefaults (see step 3)
Write default values to NSUserDefaults.
Set a flag in NSUserDefaults that the app has been opened.

saving NSUserDefaults finished

I have noticed that the saving of NSUserDefaults takes a while.
How can I check if it has finished saving?
for example I do:
NSMutableArray *uld = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:#"testdata"]];
[uld addObject:teststring];
[[NSUserDefaults standardUserDefaults] setObject:uld forKey:#"testdata"];
You normally don't have to worry about NSUserDefaults it will store changes whenever there is time, if you need to make sure a changes has been written to disk call - (BOOL) synchronise, it will return YES if the defaults were correctly written to disc.
See the NSUserDefaults reference page at Apple
Usually, the synchronize process is asynchronous and normally people don't care about when it is saved into file system. But if you want to control you can call syncrhonize method to call it synchronously.
The thing is that, the NSUserDefaults will save your data to memory, and then in some time, it will save into the file system. However, you always deal with the interface level, so the data in memory or in file system doesn't have any difference