I need to create a function foo
that takes a throwing closure as a parameter. I can implement it with either Swift or ObjC but I need to be able to call it from both.
Like this:
// Swift
func bar() throws
func foo(_ block: () throws -> void)
foo {
try bar()
}
and
// Objc
[self foo:^(
[other barBar];
)];
I tried to implement it with both Swift and ObjC without succes. With Swift:
@objc
func foo(block: () throws -> Void)
I get this error:
Method cannot be marked @objc because the type of the parameter 1 cannot be represented in Objective-C
If I try to implement it with ObjC:
typedef BOOL (^ThrowingBlock)(NSError **);
- (void)foo:(ThrowingBlock)block;
Then it does not translate to a block that throws (as it would with a function):
func foo(_: (NSErrorPointer) -> Bool)
Any idea how to achieve this?