Running this:
@try
{
NSLog(@"1. autocapitalizationType = %d", [self.textField autocapitalizationType]);
NSLog(@"2. autocapitalizationType = %@", [self.textField valueForKey:@"autocapitalizationType"]);
}
@catch (NSException *exception)
{
NSLog(@"3. %@", exception);
}
Outputs this:
1. autocapitalizationType = 0
3. [<UITextField 0x6c15df0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key autocapitalizationType.
I was expecting:
1. autocapitalizationType = 0
2. autocapitalizationType = 0
This exception only happens with properties that are part of the UITextInputTraits
protocol. Regular properties of a UITextField
such has clearButtonMode
can be accessed through valueForKey:
.
So why can't you access UITextInputTraits
properties with key-value coding?