tags:

views:

496

answers:

2

Hello All,

I am trying to save a MutableArray in NSUserDefault as follows:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:arrSelectedPlayers forKey:@"arrSelectedPlayers"];

Than I am trying to get this array:

arrSelectedPlayers =  [[prefs mutableArrayValueForKey:@"arrSelectedPlayers"] mutableCopy];

But I am not getting back my array.

Please help.

Regards, Pratik

A: 

After setting the mutable array into the user prefers, you need to synchronize the user defaults object to write the preferences to disk. I'm assuming that your read of the array occurs after the app has restarted.

Giao
A: 

Hey,

where is this method in iPhone sdk

arrSelectedPlayers =  [[prefs mutableArrayValueForKey:@"arrSelectedPlayers"] mutableCopy];

( Please don't use the non-documented methods. )

Well you can do this similar thing like this.

NSMutableArray *arr = (NSMutableArray *)[prefs arrayForKey:@"arrSelectedPlayers"];

Hope this helps.

Thanks,

Madhup

Madhup
Go to "NSKeyValueCoding Protocol Reference" you will find that method. (Please comment / reply if your 100% sure)
pratik