How does one set an optional property of a protocol? For example UITextInputTraits has a number of optional read/write properties. When I try the following I get a compile error (Cannot assign to 'keyboardType' in 'textInputTraits'):
func initializeTextInputTraits(textInputTraits: UITextInputTraits) {
textInputTraits.keyboardType = .Default
}
Normally when accessing an optional property of a protocol you add a question mark but this doesn't work when assigning a value (error: Cannot assign to the result of this expression):
textInputTraits.keyboardType? = .Default
The protocol looks like:
protocol UITextInputTraits : NSObjectProtocol {
optional var keyboardType: UIKeyboardType { get set }
}