https://mastodon.social/@krzyzanowskim/113007925115490633
UITextView convenience initializer does not call designated initializer since iOS 16.
The UITextView.init(usingTextLayoutManager:)
that is a "convenience" initializer for the UITextView
, does not call UITextView.init(frame:textContainer:)
that is a designated initializer.
This behavior, when the class interface traslated to Swift interface, breaks the Swift rules of object initialization. I believe that is also incorrect in Objective-C, although the compiler doesn't check that.
code snippet to reproduce:
final class CustomTextView: UITextView {
override init(frame: CGRect, textContainer: NSTextContainer?) {
// DESIGNATED INITIALIZER IS NEVER CALLED
super.init(frame: frame, textContainer: textContainer)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let textView = CustomTextView(usingTextLayoutManager: true)