Study on Automatic Conversion Type of Objective-C KVC

Source: Internet
Author: User
Tags date1 true true

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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.