Reputation: 547
I have a method in Objective-C
as follows:
- (void)myFunction:(void (^)(NSArray *data))successBlock error:(void (^)(NSError *error))errorBlock {
//...//
successBlock(someData);
}
I want to call it from Swift
, but I can't understand the syntax.
Whatever I try it complains:
SomeClass.sharedInstance().myFunction(
successBlock: {
(data) in
print(data)
},
error: {
(error) in
print(error)
})
Cannot call value of non-function type
'(((([AnyObject]!) -> Void!, error: ((NSError!) -> Void)!) -> Void)!
Upvotes: 0
Views: 933
Reputation: 285059
This Swift equivalent is
SomeClass.sharedInstance().myFunction({ data in
print(data)
}) { error in
print(error)
}
If you need the parameter names successBlock
and errorBlock
you have to declare them on the ObjC side.
Upvotes: 1