我有一个功能:
func saveData (numbertext : String, codetext: String) {
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as NSArray
let documentDir = paths.objectAtIndex(0) as! NSString
let path = documentDir.stringByAppendingPathComponent("data.plist")
var dict: NSMutableDictionary = ["name" : "data"]
//save values
dict.setObject(numbertext, forKey: data.numberKey)
dict.setObject(codetext, forKey: data.codeKey)
dict.writeToFile(path, atomically: false)
}
我想将该数组写入.plist文件:
var tarif : Array<String> = ["first","second","third"]
numbertext
和codetext
在另一个功能中。如何将它们写入数组?
答案 0 :(得分:1)
要保存它,您可以使用
简单地传递它dict.setObject (tarif, forKey:...)
并使用
检索它tarif = dict.objectForKey(...) as! [String]