tags:

views:

21

answers:

1

I have 1 Linked list object and i want to use that object as for storing and retriving through any class for state maintainance in objective-c. Is there any example for that???

A: 

State maintenance? For any class in objective-c? Why not use NSMutableDictionary?

There's a limit on what kinds of objects you're allowed to use (e.g. NSSets are not allowed but NSArrays are), but you can then store that dictionary straight off into NSUserDefaults to preserve state across runs.

E.g.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    NSUserDefaults *savedData = [NSUserDefaults standardUserDefaults];

    self.settingsDict = [NSMutableDictionary dictionaryWithDictionary:
        [savedData dictionaryForKey:@"settings"]];
    // ...
}

to grab, then

- (void)applicationWillTerminate:(UIApplication *)application
{
    NSUserDefaults *savedData = [NSUserDefaults standardUserDefaults];
    [savedData setObject:self.settingsDict forKey:@"settings"];
    [savedData synchronize];
    // ...
}

to save.

Kalle