Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active August 22, 2024 22:23
Show Gist options
  • Save krzyzanowskim/c7e74dc9224ccab1aa3afbc3c30179ea to your computer and use it in GitHub Desktop.
Save krzyzanowskim/c7e74dc9224ccab1aa3afbc3c30179ea to your computer and use it in GitHub Desktop.
FB14893227 UITextView convenience initializer does not call designated initializer since iOS 16

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment