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

问题描述

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

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

Objective-C

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

我的方法看起来像这样(快速

  @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) {}];