显然该文件不在可写位置,因此我在documents目录中创建了该文件。
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .UserDomainMask, true)[0] as Stringvar path = paths.stringByAppendingPathComponent("data.plist")var fileManager = NSFileManager.defaultManager()if (!(fileManager.fileExistsAtPath(path))){ var bundle : NSString = NSBundle.mainBundle().pathForResource("data", ofType: "plist") fileManager.copyItemAtPath(bundle, toPath: path, error:nil)}data.setObject(object, forKey: "object")data.writeToFile(path, atomically: true)
然后,必须从文档目录中读取它。
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .UserDomainMask, true)[0] as Stringvar path = paths.stringByAppendingPathComponent("data.plist")let save = NSDictionary(contentsOfFile: path)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)