开发者

iPhone + NSUserDefault + NSMutableArray

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

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:ar开发者_JS百科rSelectedPlayers 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


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.


You need to update your code slightly:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜