#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self save];
[self read];
}
- (void)save{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// 保存用户偏好设置
[defaults setURL:[NSURL URLWithString:@"http://www.baidu.com"] forKey:@"one"];
[defaults setURL:[NSURL URLWithString:@"http://www.jingdong.com"] forKey:@"two"];
}
- (void)read{
// 读取用户偏好设置
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSURL *url1 = [defaults URLForKey:@"one"];
NSURL *url2 = [defaults URLForKey:@"two"];
NSLog(@"url1:%@ url2:%@",url1,url2);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
网友评论