问题:is not convertible to 'BooleanLiteralConvertible

碰到一个奇怪的问题, 虽然又是因为粗心导致的问题, 但还是没搞明白为什么.

    @IBAction func logoutAction(sender: AnyObject) {
        let loginView: AnyObject? = self.storyboard?.instantiateViewControllerWithIdentifier("loginView") as! UIViewController
        self.navigationController?.pushViewController(loginView, animated: true)
    }

编译失败, 这里会报错:

'_??' is not convertible to 'BooleanLiteralConvertible'
'<>?' is not convertible to 'BooleanLiteralConvertible'

去掉loginView的类型声明就可以编译成功

    @IBAction func logoutAction(sender: AnyObject) {
        //self.navigationController?.viewControllers.removeAll(keepCapacity: false)
        let loginView = self.storyboard?.instantiateViewControllerWithIdentifier("loginView") as! UIViewController
        self.navigationController?.pushViewController(loginView, animated: true)
    }

从网上也没搜到什么结果, 这里有一篇介绍的文章, 但也没看懂,留着以后搞清楚吧

2015-08-19 10:300