Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous reference to member Swift 3

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 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 am getting an error at

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

Error states

Ambiguous reference to member 'authorize(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:

Error does not appear unitil I type success and faliure handelrs. This complies 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 guide me Thanks.

like image 255
Umair Afzal Avatar asked Jan 31 '17 07:01

Umair Afzal


2 Answers

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

          })
like image 94
yaali Avatar answered Oct 14 '22 03:10

yaali


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.

like image 39
Kappe Avatar answered Oct 14 '22 03:10

Kappe