Ambiguous reference to member Swift 3

前端 未结 3 1611
囚心锁ツ
囚心锁ツ 2021-01-02 04:05

I am migrating my project from Swift 2.3 to Swift 3. And having difficulty as expected.

Here is a function which is being used for OAuth, using OAuthSwift. I have t

相关标签:
3条回答
  • 2021-01-02 04:16

    I think the problem is caused by some shortcomings of Swift's type inference in combination with closures. You could try one of the following:

    Either don't use trailing closures, e.g.

    oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
    
             successHandler(credential, response, parameters)
    }, failure: { (error) in
    
        failure(error: error)
        print(error.localizedDescription)
    })
    

    or provide an explicit type for error, e.g.

     oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
    
             successHandler(credential, response, parameters)
     }) { (error: Error) in
    
         failure(error: error)
         print(error.localizedDescription)
     }
    
    0 讨论(0)
  • 2021-01-02 04:19

    For reference: This kind of error appears when there's more than one variable/method with the same name, does your oauthswift has more than one "thing" called "authorize"? like another method? My error was that i declared:

    let fileManager = FileManager()
    

    and in

    let _ = try localFileManager.createDirectory(...) 
    

    I got the same error, changing the variable name in localFileManager fixed it.

    0 讨论(0)
  • 2021-01-02 04:22

    I got the same error Ambiguous reference to member with the same method on converting it from Swift 4 to Swift 5. Looks like the completion handler has been changed to support the new Result type. Changing the completing handler to below fixed the issue for me,

            oauthVarSwift.authorize( withCallbackURL: URL(string: "")!,
                                 scope: "", state:"", completionHandler: {  result in
                                    switch result {
                                    case .success(let credential, let response,  let parameters):
                                        print(credential.oauthToken)
    
                                    case .failure(let error):
                                     print(error)
                                    }
    
              })
    
    0 讨论(0)
提交回复
热议问题