Reputation: 40226
I am using an SDK developed in Objective-C. My Application is hybrid (support both Objc and Swift) and I need to use a completionBlock of SDK. In SDK side it was defined like,
typedef void (^SomethingCompletionBlock)(NSArray<id<Something> > *_Nullable result, NSError *_Nullable error);
In App side I need to use like,
SDKService.fetchSomething(withModel: model) { (result, error) in
if error != nil {
completionBlock(result, error?)
}
}
I wonder what would be the signature of completionBlock in my Swift part? I am trying something like below but getting error.
typealias SomethingSearchCompletionBlock = (result: Array<Something>?, error: Error?)
Error:
Cannot call value of non-function type 'SomethingSearchCompletionBlock' (aka '(result: Optional>, error: Optional)')
Upvotes: 0
Views: 430
Reputation: 732
Might this will help
typealias SomethingCompletionBlock = (_ result: [Something]?, _ erro: Error?) -> Void
Upvotes: 2
Reputation: 285150
You have to add the Void
return value and the parameter labels are not needed
typealias SomethingSearchCompletionBlock = (Array<Something>?, Error?) -> Void
Upvotes: 2