我试图将a的布尔值传递UISwitch给另一个类使用NSUserDefaults.由于某种原因,在包含开关的类中,if应该将值设置为的语句NSUserDefaults无法读取开关声明.
@IBOutlet var shrimpSwitch: UISwitch!
@IBOutlet var nutSwitch: UISwitch!
@IBOutlet var dairySwitch: UISwitch!
let switchState = NSUserDefaults.standardUserDefaults()
if shrimpSwitch.switch.on{
switchState.setBool(true, forKey: "shrimpSwitch")
}
else{
switchState.setBool(false, forKey: "shrimpSwitch")
}
if nutSwitch.on{
switchState.setBool(true, forKey: "nutSwitch")
}
else{
switchState.setBool(false, forKey: "nutSwitch")
}
if dairySwitch.on{
switchState.setBool(true, forKey: "dairySwitch")
}
else{
switchState.setBool(false, forKey: "dairySwitch")
}
Run Code Online (Sandbox Code Playgroud)
在第一个If语句(shrimpSwitch.on)中,它将说明预期声明.我是否宣布开关都错了?任何帮助,将不胜感激.谢谢
\n\n\n错误域= NSCocoaErrorDomain代码= 513“您\ xe2 \ x80 \ x99t无权将文件\ xe2 \ x80 \ x9csubash \ xe2 \ x80 \ x9d保存在文件夹\ xe2 \ x80 \ x9ctmp \ xe2 \ x80 \ x9d中。 ” UserInfo={NSFilePath=file:///private/var/mobile/Containers/Data/Application/902FE064-C3EC-42B5-A8F8-3D2923947067/tmp/subash,NSUnderlyingError=0x281e5c6f0 {错误域=NSPOSIXErrorDomain代码=1“操作不允许”}}
\n
do {\n var mytmppath:String=FileManager.default.temporaryDirectory.absoluteString+"subash"\n try FileManager.default.createDirectory(atPath: mytmppath, withIntermediateDirectories: true, attributes: nil)\n\n print( FileManager.default.subpaths(atPath: FileManager.default.temporaryDirectory.absoluteString))\n} catch {\n print(error)\n}\nRun Code Online (Sandbox Code Playgroud)\n