【问题标题】:I keep getting this 'Bool cannot be used as a boolean; test for '!=nil' instead ' [duplicate]我不断收到这个'Bool 不能用作布尔值;测试'!= nil'而不是' [重复]
【发布时间】:2015-10-08 07:24:21
【问题描述】:

我不断收到此错误:

Bool 不能用作布尔值;改为测试 '!=nil'

我已经在网上查看了几个关于这个问题的答案,但我似乎不明白如何解决这个问题。

override func viewDidAppear(animated: Bool) 
{
    if(!PFUser.currentUser())
    {
        var loginAlert:UIAlertController = UIAlertController(title: "Please Sign up or Log In", message: "Publish your Quote Today", preferredStyle: UIAlertControllerStyle.Alert)

        loginAlert.addTextFieldWithConfigurationHandler({
            textfield in
            textfield.placeholder = "Author or Publisher"
        })

        loginAlert.addTextFieldWithConfigurationHandler({
            textfield in
            textfield.placeholder = "Your Lock"
            textfield.secureTextEntry = true
        })

错误在第二行突出显示。

【问题讨论】:

    标签: ios xcode swift boolean


    【解决方案1】:

    您正在使用在 swift 中无效的 Objetive-C 语法。 更好的使用:

    if PFUser.currentUser() == nil {
        // do something
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 2015-05-25
      • 2015-04-17
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多