Ambiguous reference to Swift 3 member

I am moving my project from Swift 2.3 to Swift 3. And with difficulty, as expected.

Here is the function that is used for OAuth using OAuthSwift . I tried to convert

class func OAuthSwiftAuthorization(inViewController viewController: UIViewController, withOAuthInfo info:FitnessTracker, successHandler:@escaping MyOAuthNewSuccessHandler, failure: @escaping ((_ error: NSError) -> Void)) {

    let oauthswift = OAuth2Swift(
        consumerKey:    info.consumerKey,
        consumerSecret: info.consumerSecret,
        authorizeUrl:   info.authorizeUrl,
        accessTokenUrl: info.accessTokenUrl,
        responseType:   info.responseType
    )

    oauthswift.authorizeURLHandler = SafariURLHandler(viewController: viewController, oauthSwift: oauthswift)
    oauthswift.accessTokenBasicAuthentification = true
    oauthswift.allowMissingStateCheck = true

    oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in

             successHandler(credential, response, parameters)
    }) { (error) in

        failure(error: error)
        print(error.localizedDescription)
    }
}

But I get an error

oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in

Error Status

Ambiguous reference to member authority (withCallbackURL: scope: state: parameters: headers: success: failure :) '

Here is the working code from Swift 2.

    oauthswift.authorizeWithCallbackURL(
        URL(string: info.callBackUrl)!,
        scope: info.scope, state:info.state,
        success: { credential, response, parameters in

            successHandler(credientials: credential, response: response, params: parameters)
        },
        failure: { error in

            failure(error: error)
            print(error.localizedDescription)
        }
    )

UPDATE:

The error does not appear unitil. I print successful and uncontrollable characters. This corresponds to a fine:

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

So please help me. Thanks.

+10
source share
3 answers

, Swift . :

, .

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)
})

,

 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)
 }
+12

: , / , oauthswift "", ""? ? , :

let fileManager = FileManager()

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

, localFileManager, .

+1

I got the same error An ambiguous reference to a member with the same method when converting it from Swift 4 to Swift 5 . It looks like the completion handler has been modified to support the new Result type . Changing the completion handler to the bottom fixed the problem 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
source

Source: https://habr.com/ru/post/1014581/


All Articles