Value of type '() -> ()' can never be nil

1.升级Xcode之后,之前代码报错,报 Value of type '() -> ()' can never be nil, comparison isn't allowed

2.相关代码

if (self.action == nil) {
            return;
        }

self.action == nil 报错了。

 if refreshTempAction != nil {
                    refreshStatus = .Refresh
                    self.startAnimation()
                    UIView.animateWithDuration(0.25, animations: { () -> Void in
                        if scrollView.contentInset.top == 0 {
                            scrollView.contentInset = UIEdgeInsetsMake(self.getNavigationHeight(), 0, scrollView.contentInset.bottom, 0)
                        }else{
                            scrollView.contentInset = UIEdgeInsetsMake(ZLSwithRefreshHeadViewHeight + scrollView.contentInset.top, 0, scrollView.contentInset.bottom, 0)
                        }
                        
                    })

refreshTempAcstion != nil 报错。

阅读 2.3k
1 个回答

看了你的“乱糟糟”的问题和与 @酷酷的哀殿 的评论后回答:

你定义的 action 都是不可空类型,你当然不能去判断是否为空,Xcode 必然报错。
你可以把你的 (() -> ()) 或者 (() -> Void) 改为 (() -> Void)?

PS: 以后来 SegmentFault 提问前,先稍微学习下 Markdown,或者使用它的格式化工具,你问题的排版太乱,让想帮你解答的人也很无奈,很难看明白你的问题;还有,不论是写代码还是做任何事,都要用心(你有单词拼写错误);我是不是管太宽了 ?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题