ios - Error when getting plist data after writing value to it -


i trying make plist file share data between skscene , settings view controller. since allow user access settings time during game, if user made changes, data plist file b4 starting game.

func startgame() {     gamestarted = true;      plistpath = nsbundle.mainbundle().pathforresource("settings", oftype: "plist");     dict = nsmutabledictionary(contentsoffile: plistpath);      let speed: cgfloat = dict.valueforkey("speed") cgfloat;  } 

if user not go settings change settings @ all, can run function no interruptions , errors.
once change speed value in settings view controller, , once function called, plistpath = nsbundle.mainbundle().pathforresource("settings", oftype: "plist"); throws exc_bad_instruction error.

and how change value plist

let plistpath = nsbundle.mainbundle().pathforresource("settings", oftype: "plist"); var dict: nsmutabledictionary = nsmutabledictionary(contentsoffile: plistpath);  dict = nsmutabledictionary(dict.setvalue(speed, forkey: "speed")); dict.writetofile(plistpath, atomically: true); 

edit: noticed problem comes line let speed: cgfloat = dict.valueforkey("speed") cgfloat; seems once remove no errors thrown, need read value plist?

try using

var plistpath = nsbundle.mainbundle().pathforresource("settings", oftype: "plist"); 

instead of

let plistpath = nsbundle.mainbundle().pathforresource("settings", oftype: "plist"); 

this resolved problem.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -