0
    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()
        }
    }

I make xcframework. This code inside it. I link this xcframework to application and use it, but there is no convenience init for MyButton class. XCode 11.3

2 Answers2

0

Create extension of MyButton and not UIButton,

public extension MyButton {
    var someProperty: Int {
        return 1
    }

    convenience init(label: String) { 
        self.init()
    }
}

In application, access it using

MyButton(label: "Button_Label")

Edit:

Even if you subclass MyButton, init(label:) will be available in the subclass until you define its own initializers.

public class MySuperButton: MyButton {

}

You can access init(label:) in main project like,

MySuperButton(label: "Super Button")
PGDev
  • 23,751
  • 6
  • 34
  • 88
  • What if once i will declare subclass of MyButton, for example MySuperButton, it will not have this convenience init. – Alexey Nenastev Jan 23 '20 at 13:37
  • @AlexeyNenastev You can access the `convenience init` in the subclass until you define subclass` own initialisers. I've edited the answer for that. – PGDev Jan 24 '20 at 10:48
0

The public flag is required in the convenience init. This will allows the init be visible in xcframework.

Try this

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()
    }
}

However, you're updating the UIButton instead of your declared class MyButton. Make sure that is exactly what you want to do.