>  Q&A  >  본문

ios - 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 报错。

怪我咯怪我咯2713일 전382

모든 응답(1)나는 대답할 것이다

  • 阿神

    阿神2017-04-18 09:29:49

    귀하의 '엉터리' 질문과 @Cool Ai Dian의 댓글을 읽고 다음과 같이 답했습니다.

    정의한 작업은 모두 null을 허용하지 않는 유형입니다. 물론 Xcode에서 오류가 발생하는지 여부를 판단할 수는 없습니다.
    (() -> ()) 또는 (() -> Void)(() -> Void)?로 변경할 수 있습니다.

    PS: 나중에 질문하기 위해 SegmentFault에 오기 전에 마크다운에 대해 조금 배우거나 해당 서식 도구를 사용하세요. 답변을 도와주려는 사람들도 어렵습니다. 질문을 이해하기도 어렵습니다. 코드를 작성하든지 무엇을 하든 조심해야 합니다(철자 오류가 있습니다).

    회신하다
    0
  • 취소회신하다