ios - How to write blocks (closures) in swift3 right way? -


i trying find how can write blocks in swift3, appreciated.

i using obj-c pocketsdk in swift3 project. https://github.com/pocket/pocket-objc-sdk

i can use sdk fine proper bridge-header settings, still not sure how can write blocks part.

obj-c

[[pocketapi sharedapi] callapimethod:@"get"                        withhttpmethod:pocketapihttpmethodget                             arguments:arguments                               handler:^(pocketapi *api, nsstring *apimethod, nsdictionary *response, nserror *error) {                               }]; 

this type def in pocketsdk.

-(void)callapimethod:(nsstring *)apimethod withhttpmethod:(pocketapihttpmethod)httpmethod arguments:(nsdictionary *)arguments delegate:(id<pocketapidelegate>)delegate;       typedef void(^pocketapiresponsehandler)(pocketapi *api, nsstring*apimethod, nsdictionary *response, nserror *error); 

swift? (this shows error.)

    let arguments: [string: any] = [         "state": "unread",         "count": 20     ]      pocketapi.shared().callmethod("get", with: pocketapihttpmethodget, arguments: arguments) {         (api: pocketapi,         apimethod: string,         esponse: [anyhashable:any],         error: error) in     } 

@updated

i avoid compile error without type def, still unrecognized selector if put arguments. if set nil in arguments, don't though. wrong dictionary?

    var arguments = [string : any]()     arguments["count"] = 20     arguments["state"] = "unread"      pocketapi.shared().callmethod("get", with: pocketapihttpmethodget, arguments: arguments) {         (api,         apimethod,         response,         error) in     } 

error.

-[_swifttypepreservingnsnumber length]: unrecognized selector sent instance 0x174624540 2017-08-15 14:05:51.345611+0900 voicepaper2[1062:286998] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[_swifttypepreservingnsnumber length]: unrecognized selector sent instance 0x174624540' * first throw call stack:

solved! final answer, thanks!

    let arguments: [string: any] = [         "state": "unread",         "count": "20"     ]      pocketapi.shared().callmethod("get", with: pocketapihttpmethodget, arguments: arguments) {         (api,         apimethod,         response,         error) in     } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -