Reputation: 7801
I encounter strange compile error when accessing UITextView as object conforming to UITextInputTraits:
protocol MyEditingView:UITextInputTraits where Self: UIView {
}
extension UITextView:MyEditingView {
}
class SomeClass {
var editingView:MyEditingView = UITextView()
func someFunc() {
editingView.autocorrectionType = .no
}
}
"Cannot assign to property: 'self' is immutable"
But if property is explicitly declared in protocol, without inheriting from UITextInputTraits it is compiled successfully.
protocol MyEditingView where Self: UIView {
var autocorrectionType: UITextAutocorrectionType { get set }
}
And property declaration is same as in UITextInputTraits.
Swift 4.2, XCode 10.1
Upvotes: 1
Views: 262
Reputation: 57
autocorrectionType property is optional inside UITextInputTraits but when you declare it explicitly in MyEditingView its no more optional property. I tried making it optional property in MyEditingView and got the same compilation error.
Upvotes: 1