NSString *username = @"name";
NSString *password = @"password";
//1.plist --> 文件要放到沙盒里
//沙盒:每个应用程序对应于沙盒中的一个特定文件夹。在访问沙盒中的文件时,每个应用程序只能访问自己对应的文件夹
//Documents:用于存放需要永久性存储的文件
//tmp:用于存放临时性的文件
NSString *path = NSHomeDirectory();
// NSLog(@"path = %@",path);
path = [path stringByAppendingPathComponent:@"/Documents/1.plist"];
NSArray *plistArr = @[username,password];
//atomically:YES --> 文件会被先放到缓冲区,等所有文件就位后,一次性写入
// NO --> 立即写入
[plistArr writeToFile:path atomically:YES];
//2.归档
NSString *path2 = NSHomeDirectory();
path2 = [path2 stringByAppendingPathComponent:@"Documents/2.archive"];
NSLog(@"%@",path2);
[NSKeyedArchiver archiveRootObject:plistArr toFile:path2];
本文介绍了一种在iOS应用中使用属性列表(plist)文件和归档来存储用户名和密码的方法。详细展示了如何创建并写入.plist文件到沙盒环境中的Documents目录下,以及如何通过归档方式将数据保存为.archive文件。
1171

被折叠的 条评论
为什么被折叠?



