登录记住账号和密码小Demo

读取 

 1  // 1.读取沙盒中plist文件
 2 
 3     // 1.1.获得沙盒根路径
 4 
 5     NSString *home = NSHomeDirectory();
 6 
 7     // 1.2.拼接Documents路径
 8 
 9     NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];
10 
11     // 1.3.文件的全路径
12 
13     NSString *filepath = [docPath stringByAppendingPathComponent:@"login.plist"];
14 
15     // 2.从plist中加载一个字典出来
16 
17     NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filepath];
18 
19     
20 
21     // 3.赋值
22 
23     self.userName.text = dict[@"qq"];
24 
25     self.passWord.text = dict[@"pwd"];

 

存储

 1 NSDictionary *dict = @{
 2 
 3                            @"qq" : self.userName.text,
 4 
 5                            @"pwd" : self.userName.text
 6 
 7                            };
 8 
 9     // 2.存储数据到沙盒的plist文件中
10 
11     // 2.1.获得沙盒根路径
12 
13     NSString *home = NSHomeDirectory();
14 
15     
16 
17     // 2.2.拼接Documents路径
18 
19     NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];
20 
21     
22 
23     // 2.3.文件的全路径
24 
25     NSString *filepath = [docPath stringByAppendingPathComponent:@"login.plist"];
26 
27  
28 
29     [dict writeToFile:filepath atomically:YES];

 

posted @ 2014-09-09 11:11  TianXiang.Liu  阅读(493)  评论(0编辑  收藏  举报