Reputation: 305
I have a function:
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)
}
I want to write that array to a .plist file:
var tarif : Array<String> = ["first","second","third"]
numbertext
and codetext
are in another function. How can I write them to an array?
Upvotes: 0
Views: 1153
Reputation: 36305
To save it you can simple pass it with
dict.setObject (tarif, forKey:...)
and retrieving it with
tarif = dict.objectForKey(...) as! [String]
Upvotes: 1