Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 写入值后获取plist数据时出错_Ios_Nsdictionary_Swift_Exc Bad Instruction - Fatal编程技术网

Ios 写入值后获取plist数据时出错

Ios 写入值后获取plist数据时出错,ios,nsdictionary,swift,exc-bad-instruction,Ios,Nsdictionary,Swift,Exc Bad Instruction,我正在尝试创建一个plist文件,以便在我的SKScene和设置视图控制器之间共享数据。 由于我允许用户在游戏期间的任何时间访问设置,如果用户进行了任何更改,我总是从开始游戏的plist文件b4获取数据 func startGame() { gameStarted = true; plistPath = NSBundle.mainBundle().pathForResource("Settings", ofType: "plist"); dict = NSMutable

我正在尝试创建一个plist文件,以便在我的
SKScene
和设置视图控制器之间共享数据。 由于我允许用户在游戏期间的任何时间访问设置,如果用户进行了任何更改,我总是从开始游戏的plist文件b4获取数据

func startGame() {
    gameStarted = true;

    plistPath = NSBundle.mainBundle().pathForResource("Settings", ofType: "plist");
    dict = NSMutableDictionary(contentsOfFile: plistPath);

    let speed: CGFloat = dict.valueForKey("Speed") as CGFloat;

}
如果用户根本不去“设置”更改设置,我可以运行此功能,不会出现中断和错误。
但是一旦我在设置视图控制器中更改了速度值,并且调用了这个函数,
plistPath=NSBundle.mainBundle().pathForResource(“设置”,类型为:“plist”)总是抛出
EXC\u BAD\u指令
错误

这就是我如何改变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);
编辑:我注意到问题来自这行
让speed:CGFloat=dict.valueForKey(“speed”)作为CGFloat删除后似乎不会抛出错误,但我需要它从plist读取值?

尝试使用

var plistPath = NSBundle.mainBundle().pathForResource("Settings", ofType: "plist");
而不是

let plistPath = NSBundle.mainBundle().pathForResource("Settings", ofType: "plist");
这解决了我的问题