Xcode 8 Warning “Instance method nearly matches optional requirement”

后端 未结 10 1543
情深已故
情深已故 2020-12-03 05:01

I converted my (macOS) project to Swift 3 in Xcode 8 and I get the following warnings with several delegate methods I implement in swift classes:

Instance me         


        
10条回答
  •  长情又很酷
    2020-12-03 05:33

    Another cause of this warning when NSError is being bridged to Swift:

    Given this Objective-C delegate method:

    - (void)myService:(id)myService didFailForSomeReason:(NSError *)error;
    

    That automatically generates this Swift method:

    public func myService(_ myService: MYService!, didFailForSomeReason error: Error!)
    

    The warning was shown.

    In my case the reason was that my class had it's own Error type so the signature was resolving to MyClass.Error rather than Swift.Error. The solution was to fully type the Error parameter by changing it to Swift.Error:

    public func myService(_ myService: MYService!, didFailForSomeReason error: Swift.Error!)
    

提交回复
热议问题