I'm writing a protocol that has a readOnly label. I want to extend it and give it a default implementation where the conforming type is a UITextView
.
Code:
protocol CountingView {
var keyboardLabel : UILabel {get}
}
extension CountingView where Self : UITextView {
var keyboardLabel : UILabel {
get {
let label = UILabel()
label.textColor = UIColor.white
label.translatesAutoresizingMaskIntoConstraints = false
return label
}
private (set) {
keyboardLabel = newValue
}
}
}
However when I add the private
before the set
I get the following error.
Expected 'get', 'set', 'willSet', or 'didSet' keyword to start an accessor definition
I looked up other questions with this error but didn't find them related to mine.