【发布时间】:2021-03-12 23:02:00
【问题描述】:
我有一个自定义类,其中包含一个用 swift 编写的自定义初始化。我需要从 Objective-C 类中调用该 init。
斯威夫特
@objc public class MyClass: NSObject {
public init(configuration config: Data)
{
super.init()
// Do Stuff
}
}
Objective-C
[[MyClass alloc] initWithConfiguration:CONFIG];
但是当我从 Objective-C 调用 init 时,编译器会抱怨
“MyClass”没有可见的@interface 声明选择器 'initWithConfiguration:'
我在这里错过了什么?
【问题讨论】:
-
请证明您已将生成的标头导入到您的Objective-c .m文件中。
-
@matt 查看生成的头文件,它显示为 init 函数未在界面中列出。这可以解释为什么我的 obj-c 代码看不到它。
标签: objective-c swift