1.UserDefaults 适合存储轻量级的本地客户端数据,比如记住密码功能,要保存一个系统的用户名、密码
UserDefaults.standard.set(dic.name, forKey: "dic.name")
UserDefaults.standard.object(forKey: "dic.name")
2.沙盒存储
//获得沙盒的根路径
let home = NSHomeDirectory() as NSString;
//获得Documents路径
let docPath = home.appendingPathComponent("Documents") as NSString;
let dataSource = NSMutableArray();
dataSource.add("衣带渐宽终不悔");
dataSource.add("为伊消得人憔悴");
dataSource.add("故国不堪回首明月中");
dataSource.add("人生若只如初见");
dataSource.add("暮然回首,那人却在灯火阑珊处");
//将数据写入文件中
dataSource.write(toFile: docPath as String, atomically: true);