相关疑难解决方法(0)

使用Swift的预期声明错误

我试图将a的布尔值传递UISwitch给另一个类使用NSUserDefaults.由于某种原因,在包含开关的类中,if应该将值设置为的语句NSUserDefaults无法读取开关声明.

ViewController.swift

@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)中,它将说明预期声明.我是否宣布开关都错了?任何帮助,将不胜感激.谢谢

xcode nsuserdefaults swift

16
推荐指数
1
解决办法
2万
查看次数

我无法在文件管理器中创建目录

\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
\n\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}\n
Run Code Online (Sandbox Code Playgroud)\n

ios swift

-1
推荐指数
1
解决办法
2211
查看次数

标签 统计

swift ×2

ios ×1

nsuserdefaults ×1

xcode ×1