Study on Automatic Conversion Type of objective-C KVC

Source: Internet
Author: User
Tags date1
# 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 yes False false 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.


Study on Automatic Conversion Type of objective-C KVC

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.