我似乎无法弄清楚如何从 Swift 调用 Objective-C 块!
我有以下 Objective-C 方法:
- (void)myMethod:(NSDictionary *)selection success:(MyBlock)success;
MyBlock在哪里:
typedef void(^MyBlock)(BOOL success, NSDictionary* options);
它要么抱怨它不能投射:
"Cannot convert value of type '(Bool, Dictionary<AnyHashable, Any>) -> ()' to expected argument type 'MyBlock!' (aka 'ImplicitlyUnwrappedOptional<(Bool, Optional<Dictionary<AnyHashable, Any>>) -> ()>')"
或者当我尝试使用以下任何一种方法从 Swift 调用该方法时,我得到一个 SIGABRT:
myInstance.myMethod(myOptions) { (success, options) in
...
}
myInstance.myMethod(myOptions) { (success: Bool, options: Dictionary<AnyHashable, Any>?) in
...
}
myInstance.myMethod(myOptions) { (success: Bool!, options: [AnyHashable: Any]?) in
...
}
myInstance.myMethod(myOptions, success: { (success, options) in
...
})
myInstance.myMethod(myOptions, success: { (success, options) in
...
} as MyBlock)
myInstance.myMethod(myOptions, success: { (success: Bool, options: Dictionary<AnyHashable, Any>?) in
...
})
myInstance.myMethod(myOptions, success: { (success: Bool!, options: Dictionary<AnyHashable, Any>?) in
...
})
myInstance.myMethod(myOptions, success: { (success: Bool!, options: Dictionary<AnyHashable, Any>?) in
...
} as MyBlock)
myInstance.myMethod(myOptions, success: { (success: Bool!, options: [AnyHashable: Any]?) in
...
})
myInstance.myMethod(myOptions, success: { (success: Bool, options: [AnyHashable: Any]?) in
...
})
我该怎么办?