目标C块语法-Xcode自动完成不起作用


请提供一些OBJECTIVE-C块语法帮助。

这是我的呼叫站点(AppDelegate(-由XCode 自动完成

Objective-C

[SwiftClass passValue: response completion:^(NSDictionary<NSString *,NSString *> * _Nullable, ErrorResponse * _Nullable) { }];

我的方法看起来像这样(Swift(

@objc static func passValue(code: ValidatedResponse, completion: @escaping ([String : String]?, ErrorResponse?) -> Void)

我收到一个错误,上面写着:Parameter name omitted

所以,我给这些参数命名如下:

[SwiftClass passValue: response completion:^(NSDictionary<NSString *,NSString *> *responseDictionary _Nullable, ErrorResponse *errorResponse _Nullable) {}];

现在我得到这个错误:

Incompatible block pointer types sending 'void (^)(NSDictionary<NSString *,NSString *> *__strong)' to parameter of type 'void (^ _Nonnull)(NSDictionary<NSString *,NSString *> * _Nullable __strong, ErrorResponse * _Nullable __strong)'

你们知道我在ObjectiveC中调用方法的方式有什么问题吗?

顺便说一句,是的,我知道这些文件和http://fuckingblocksyntax.com/,我已经看了一遍,弄不清问题出在哪里。

我找到了!参数名称必须在Nullable之后,如下所示:

[SwiftClass passValue: response completion:^(NSDictionary<NSString *,NSString *> * _Nullable responseDictionary, ErrorResponse * _Nullable errorResponse) {}];

最新更新