Hello!
I struggling with Objective-C default initializers popped up in xcframework while we don’t have such initializers in the framework code. It looks like this in the xcframework interface file
So if I use this framework not as xcframework but as Swift Package with source code then Xcode doesn’t allow to me to use this init() inherited from NSObject. But in a xcframework this init() appears and allows to me to use it and then crashes because there is no such init in this object.
So for example I have some MyStackView in a framework which is a subclass of UIStackView. And I have my initializer like init(withParameter: … ). But I can use default initializers of UIStackView like init(frame:) after conversion to xcframework. And it crashes.
For example, I have such code in the Framework
now in the swiftinterface file we can see this
If I try to do something like that in the client, it will crash, but compiler says that all is OK.
How can I cope with it in the right way?
I struggling with Objective-C default initializers popped up in xcframework while we don’t have such initializers in the framework code. It looks like this in the xcframework interface file
Code Block @objc override dynamic public init()
So if I use this framework not as xcframework but as Swift Package with source code then Xcode doesn’t allow to me to use this init() inherited from NSObject. But in a xcframework this init() appears and allows to me to use it and then crashes because there is no such init in this object.
So for example I have some MyStackView in a framework which is a subclass of UIStackView. And I have my initializer like init(withParameter: … ). But I can use default initializers of UIStackView like init(frame:) after conversion to xcframework. And it crashes.
For example, I have such code in the Framework
Code Block public class Logger: NSObject { private let string: String public init(withString string: String) { self.string = string } public func printSomething() { print(string) } } public class MyStackView: UIStackView { public init(withName name: String) { super.init(frame: .zero) /*custom logic here*/ } required public init(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
now in the swiftinterface file we can see this
Code Block public var TestFrameworkVersionNumber: Double @objc public class Logger : NSObject { public init(withString string: String) public func printSomething() @objc override dynamic public init() <---- ??? } @objc public class MyStackView : UIStackView { public init(withName name: String) @objc required dynamic public init(coder: NSCoder) @objc override dynamic public init(frame: CGRect) <---- ??? }
If I try to do something like that in the client, it will crash, but compiler says that all is OK.
Code Block /* crash here!!! */ let logger2 = Logger() logger2.printSomething() /* crash here!!! */ let stackView = MyStackView(frame: .zero)
How can I cope with it in the right way?