Now this is a weird behaviour of Swift compiler. I get a Cannot assign to property 'self' is immutable compile time error in a class. Here is the minimal playground code:
import UIKit
open class TextInputTraitsWrapper: NSObject {
private var wrapped: UITextInputTraits
public init(wrapped: UITextDocumentProxy) {
self.wrapped = wrapped
super.init()
}
open var keyboardAppearance: UIKeyboardAppearance {
get {
return wrapped.keyboardAppearance ?? UIKeyboardAppearance.default
}
set {
wrapped.keyboardAppearance = newValue // ERROR ON THIS LINE
}
}
}
And this is the error that I get (this is the complete program):
As a side note protocol UITextInputTraits defines keyboardAppearance like this: optional var keyboardType: UIKeyboardType { get set }.
Why do I get this kind of error in a class??
