write an array to .plist file Swift

1.1k Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

To save it you can simple pass it with

dict.setObject (tarif, forKey:...)

and retrieving it with

tarif = dict.objectForKey(...) as! [String]