15
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NSUserdefaultsにNSMutablearrayを格納する/読み出す

Posted at
  • 格納
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    NSMutableArray *array = [[NSMutableArray alloc] init];
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:array];
    [ud setObject:data forKey:@"array_key"];

MutableArrayの名前がarray, array_keyは読み出すときのkey.

  • 読み出し
 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    NSData *data = [ud objectForKey:@"array_key"];
    NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];

あとは煮るなり焼くなり。
要素を変更したときは、格納コードをもう一回書いて、
[ud synchronize];
しましょう。

15
17
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?