Xcode 8 Warning “Instance method nearly matches optional requirement”

后端 未结 10 1546
情深已故
情深已故 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:20

    One reason you might get this error has to do with method access modifiers. For example if you didn't define the function as public. So for methods on the CLLocationManagerDelegate case, changing:

    func locationManager(_ manager: CLLocationManager,
                         didChangeAuthorization status: CLAuthorizationStatus)
    

    to:

    public func locationManager(_ manager: CLLocationManager,
                                didChangeAuthorization status: CLAuthorizationStatus)
    

    (i.e. make the method public) gets rid of the warning and the method get called as expected. Note that autocomplete doesn't put the public access modifier on the method.

提交回复
热议问题