简体   繁体   中英

Swift Error - extra argument 'option' in call for SimpleAuth

Hi I have been battling with a swift error as I cannot match the arguments of an objective-c method

    SimpleAuth.authorize("instagram", 

       options: ["scope" : "likes"], completion: { 

          (responseObject : NSDictionary!, error : NSError!) -> Void in

          self.accessToken = responseObject["credentials"]["token"]

          ......

    })

//error Extra argument 'options' in call

Declared as:

  + (void)authorize:(NSString *)provider options:(NSDictionary *)options completion:(SimpleAuthRequestHandler)completion;

Code completion is :

  SimpleAuth.authorize(<#provider: String!#>, options: <#[NSObject : AnyObject]!#>, completion: <#SimpleAuthRequestHandler!##(AnyObject!, NSError!) -> Void#>)

I have tried type casting, down casting, declaring as a separate variables, but still cant get it to work.

Any ideas, will be much appreciated

It's your definition of your completion block. SimpleAuthRequestHandler is defined as:

typedef void (^SimpleAuthRequestHandler) (id responseObject, NSError *error);

But your completion block/closure is defined as:

(responseObject : NSDictionary!, error : NSError!) -> Void in

You can't just change the type from id ( AnyObject in Swift) to NSDictionary! without explicitly casting it. Your call should look something like this:

SimpleAuth.authorize("instagram", options: ["scope" : "likes"], completion: {
    (responseObject : AnyObject!, error : NSError!) -> Void in

    /* ... */
})

You can then make responseObject an NSDictionary with a cast:

var response = responseObject as NSDictionary

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM