swift - 为什么我的 Objective-C 块在传递给 Swift 函数时没有显示?
问题描述
我未能将objective-c 块传递给swift 函数。
我将音频单元 V3 的 Apple 示例代码中的文件复制到一个新项目中,结果出现问题。
有一个 Objective-C 函数将匿名块传递给 Swift 文件/函数——Swift func 不再工作,因为它没有正确接收块。
当我在 Swift 函数中放置断点时,传入块的变量显示为completionHandler (() -> ())
但没有地址。
它应该显示completionHandler (()->()) 0xd8d87999
或其他。(它应该将它传递给另一个 Swift 函数,它不再能够调用它。)
Swift 代码的其余部分正在运行 AFAIK。
任何想法都非常感谢。
Objective-C 函数:(
试图传递^{[self connectParametersToControls];}
给 Swift 对象,“playEngine”)
playEngine = [[SimplePlayEngine alloc] initWithComponentType: desc.componentType componentsFoundCallback: nil];
[playEngine selectAudioUnitWithComponentDescription_objc:desc
completionHandler:^{
[self connectParametersToControls];
}];
斯威夫特函数:
@objc public func selectAudioUnitWithComponentDescription_objc(_ componentDescription: AudioComponentDescription, completionHandler: @escaping (() -> Void)) {
self.selectAudioUnitWithComponentDescription(componentDescription, completionHandler:completionHandler)
}
Swift 标头中的相关行:
- (void)selectAudioUnitWithComponentDescription_objc:(AudioComponentDescription)componentDescription completionHandler:(void (^ _Nonnull)(void))completionHandler;
解决方案
事实证明,虽然 Obj-c 优化已关闭,但 Swift 优化已打开,这导致了问题。我不认为它应该,但似乎是这样。
推荐阅读
- arrays - 如何在 React 中访问没有键的数组中的数组?
- angular - 如何为每个分组的行 Mat-table angular 添加总行?
- google-ads-api - 无法启用设置最高每次点击费用出价限制并使用 google adwords api 设置最高出价
- logging - 避免在 Raspberry Pi 的日志文件中出现“% Total % Received % Xferd Average”的卷曲输出
- jdbc - 如何使用 Jdbc FastExport 将数据从 teradata 传输到 Mariadb
- java - Imageloader 几个图像到 ViewPager
- python - 在 Python 中安排训练和测试脚本
- postgresql - 用于查找和创建模式缺失索引的脚本
- django - 休伊;不在一个 Django 应用程序中运行任务
- android - 无法添加窗口 android.view.ViewRootImpl$W@3660b6 -- 窗口类型 2038 的权限被拒绝