import UIKit
public class MyButton: UIButton {}
public extension UIButton {
var someProperty: Int { 1 } // visible in xcframework
convenience init(label: String) { // NOT visible in xcframework
self.init()
}
}我做了xcframework。它里面的代码。我将这个xcframework链接到应用程序并使用它,但是MyButton类没有方便的初始化。XCode 11.3
发布于 2020-01-23 20:48:59
创建MyButton的extension,而不是UIButton
public extension MyButton {
var someProperty: Int {
return 1
}
convenience init(label: String) {
self.init()
}
}在应用程序中,使用以下命令访问它
MyButton(label: "Button_Label")编辑:
即使你继承了MyButton的子类,在你定义自己的初始化器之前,init(label:)在子类中仍然是可用的。
public class MySuperButton: MyButton {
}您可以在主项目中访问init(label:),如
MySuperButton(label: "Super Button")发布于 2020-01-23 20:51:57
public标志在便利性初始化中是必需的。这将允许init在xcframework中可见。
尝尝这个
import UIKit
public class MyButton: UIButton {}
public extension UIButton {
var someProperty: Int { 1 } // visible in xcframework
public convenience init(label: String) { // NOT visible in xcframework
self.init()
}
}但是,您更新的是UIButton,而不是声明的类MyButton。确保这正是你想要做的。
https://stackoverflow.com/questions/59878881
复制相似问题