3
3

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の使い方

Posted at

NSUserDefaultsの使い方

文字列を保存したいとき

test.m
NSString *hoge = @"hoge";

//keyNameという名前でhoge(文字列)を保存する
[[NSUserDefaults standardUserDefaults] setObject:hoge forKey:@"keyName"];
[[NSUserDefaults standardUserDefaults] synchronize]; //すぐに保存する

数値を保存したいとき

test.m
NSInteger hoge = 1;

// keyNameという名前でhoge(数値)を保存する
[[NSUserDefaults standardUserDefaults] setInteger:hoge forKey:@"keyName"];
[NSUserDefaults standardUserDefaults] synchronize];

保存したものを取り出す

test.m
NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"keyName"];
NSInteger integer = [[NSUserDefaults standardUserDefaults] integerForKey:@"keyName"];
3
3
0

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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?