swift - Issue when updating values in plist containing dictionary of arrays -
i have plist has dictionary of arrays. i'm new swift , struggling update value in plist. here sample plist file i'm dealing in app:
<dict> <key>somekey1</key> <array> <string>100</string> <string>company1</string> </array> <key>somekey2</key> <array> <string>500</string> <string>company2</string> </array> </dict>
in app, display above plist values in table view. when user selects row in table, populates 2 text fields (number , company) values.this works fine. want update values in textfields, click save button , reload table data. plist file copied documents folder it's writable (as per http://rebeloper.com/read-write-plist-file-swift/). following piece of code updates values, deletes "somekey1" , can't figure out why that. missing something?
let path = pathtodocsfolder() var mykey="somekey2" //has value "somekey1" or "somekey2" var valarray=[textfieldnumber.text, textfieldcompany.text] var thisdict: nsmutabledictionary = ["xinitializeritem": "donoteverchangeme"] thisdict.setobject(valarray, forkey: mykey) thisdict.writetofile(path, atomically: false)
try this:
var mykey="somekey2" //has value "somekey1" or "somekey2" var valarray=[textfieldnumber.text, textfieldcompany.text] let path = pathtodocsfolder() let plistdict = nsmutabledictionary(contentsoffile: path) plistdict.setobject(valarray, forkey: mykey) plistdict.writetofile(path, atomically: false)
Comments
Post a Comment