Swift - 在其自己的初始值内使用的变量

时间:2017-09-12 03:22:23

标签: swift

func presentLoggedInScreen() {
    let stroyboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let logginedInVCViewController:LogginedInVCViewController = storyboard.instantiateViewController(withIdentifier: "LogginedInVCViewController" as! LogginedInVCViewController,
    self.present(logginedInVCViewController, animated: true, completion: nil))
}

如何避免此错误?

  

在其自己的初始值

中使用的变量

1 个答案:

答案 0 :(得分:3)

试试这个:

func presentLoggedInScreen() {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    if let logginedInVCViewController = storyboard.instantiateViewController(withIdentifier: "LogginedInVCViewController") as? LogginedInVCViewController {
        self.present(logginedInVCViewController, animated: true, completion: nil)
    }
}

编辑: 使用可选的绑定和导致错误的是和额外的
有时XCode的intellisense无法正常工作,所以首先尝试分析问题:)