objective-c - Objective 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) {}];
推荐阅读
- r - 是否可以使用大 csv 文件(1GB)执行 PCA?
- android - 使用两种方式绑定格式化编辑文本文本
- angular - 用于社交分享的动态元标签 Angular 6+ Universal
- bitbucket - 对于更改 Bitbucket IP(传入/传出),我可以点击一个 URL 来发现更改吗?
- python - Django - LoginView:“AnonymousUser”对象没有属性“_meta”
- ios - 如何在 viewDidLoad 之后创建/添加 UIView?
- highcharts - 在绘图区域内渲染折线图
- javascript - 未处理的承诺拒绝。此错误源于在异步函数内部抛出 - NodeJS
- c# - C# 如何使用 VAMemory.dll 读取多指针值
- c# - 如何限制每个组件的日志记录?