开发者

How to save the values if the app when its closed

开发者 https://www.devze.com 2023-01-06 04:16 出处:网络
i am new to iPhone programming.. my app is just like a quiz.. it has different type of quizs and many question in each quiz type

i am new to iPhone programming..

my app is just like a quiz.. it has different type of quizs and many question in each quiz type i want to save the values like strings(quiz开发者_运维百科 name) and integers(question number) when an application is closed so when the app is restarted i want to continue where it was stopped by using saved values

How to do this...?

Can any body help me to do this please....

Thank u


To save a string:

NSString *name = @"John";
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:name forKey:@"Name"];

To load a string:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *name = [prefs stringForKey:@"Name"];

Read more at: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html


I would suggest you look at Core data and save answers as they are entered. Then when the app is restarted you need to find a way to quickly load the relevant data (Actually, you will find you don't need to load that much, which could also help you reduce what you need to save.)

Remember, simplicity is of the essence, and lazy loading very helpful. Don't load anything you don't need until you need it.

A good Apple example was the SQLiteBooks sample which they provided with iPhoneOS 2.0 (I don't know if they still provide it).


NSUserDefaults is good for saving state and preferences.

0

精彩评论

暂无评论...
验证码 换一张
取 消