【发布时间】:2019-04-20 22:35:09
【问题描述】:
我未能将 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];
}];
Swift 函数:
@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;
【问题讨论】:
标签: swift macos objective-c-blocks core-audio audiounit