Study on Automatic Conversion Type of Objective-C KVC
# Objective-c kvc automatic conversion type
Apple is very kind. During the time of kvc, we made some type conversions and posted the rules for your reference.
@ Interface Entity: NSObject @ property (nonatomic, copy) NSString * str; @ property (nonatomic, assign) int i1; @ property (nonatomic, assign) int i2; @ property (nonatomic, assign) int i3; @ property (nonatomic, assign) float f1; @ property (nonatomic, strong) NSNumber * num; @ property (nonatomic, assign) BOOL b1; @ property (nonatomic, assign) BOOL b2; @ property (nonatomic, assign) BOOL b3; @ property (nonatomic, strong) NSDate * date1; @ property (nonatomic, assign) NSTimeInterval t1; @ end // The value string can be converted to the value type [obj setValue: @ "2.4" forKey: @ "i1"]; // a non-numeric string does not recognize [obj setValue: @ "a" forKey: @ "i2"]; // only recognizes the previous number of special characters [obj setValue: @ "2014 10-24" forKey: @ "i3"]; // This conversion used to be NSNumber type [obj setValue: @ 1 forKey: @ "str"]; [obj setValue: @ 1.23 forKey: @ "f1"]; // returns an NSString [obj setValue: @ "99" forKey: @ "num"]; //> = 1.0 true, false [obj setValue: @ 1.0 forKey: @ "b1"]; //> = 0.9 true, false [obj setValue: @ "1.1" forKey: @ "b2"]; // true TRUE yes YES yes false FALSE no NO can recognize [obj setValue: @ "TRUE" forKey: @ "b3"]; // convert to NSTring [obj setValue: @ "2014-10-24" forKey: @ "date1"]; // do not know [obj setValue: @ "2014-10-24" forKey: @ "t1"]; // conclusion // a numeric string to a numeric value can be converted into a numeric value. // a class to class is directly assigned without conversion.