I am learning Swift. I have created an dictionary:
var myDict = Dictionary<String, String>()
myDict["AAA"] = "aaa"
myDict["BBB"] = "bbb"
Now I want to persist this dictionary to a file. I get a file path under documents:
let docDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).last as? String
let filePath = docDir.stringByAppendingPathComponent("MyFile.txt")
Until here, I don't know how to store myDict
to the file. And also how to read the myDict
back from file. Could someone please guide me through please?