I am trying to find how I can write this blocks in swift3, any help would be appreciated.
I am using obj-c PocketSDK in swift3 project. https://github.com/Pocket/Pocket-ObjC-SDK
I can use this SDK fine with proper Bridge-Header settings, but still not sure how I can write blocks part.
obj-c
[[PocketAPI sharedAPI] callAPIMethod:@"get"
withHTTPMethod:PocketAPIHTTPMethodGET
arguments:arguments
handler:^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error) {
}];
This is the 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 could avoid the compile error without type def, but still get the unrecognized selector if I put arguments. If I set nil in arguments, I don't get it though. Anything wrong with the 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 to instance 0x174624540 2017-08-15 14:05:51.345611+0900 Voicepaper2[1062:286998] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftTypePreservingNSNumber length]: unrecognized selector sent to instance 0x174624540' * First throw call stack: