Study on the type of self-active conversion of objective-c KVC

Source: Internet
Author: User
Tags date1 true true


# # # Objective-c KVC Self-active conversion type research


Apple is very kind, KVC time to help us do some type of conversion, the law posted, for the participants to participate in the test








@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

// numeric strings can be converted to numeric types
    [obj setValue: @ "2.4" forKey: @ "i1"];
    // Non-numeric strings are not recognized
    [obj setValue: @ "a" forKey: @ "i2"];
    // Only know the number of special symbols
    [obj setValue: @ "2014 10-24" forKey: @ "i3"];
    
    // This conversion used to be of type NSNumber
    [obj setValue: @ 1 forKey: @ "str"];
    [obj setValue: @ 1.23 forKey: @ "f1"];
    
    // Go to NSString
    [obj setValue: @ "99" forKey: @ "num"];
    
    //> = 1.0 is true, below 1.0 is false
    [obj setValue: @ 0.9 forKey: @ "b1"];
    //> = 1.0 is true, below 1.0 is false
    [obj setValue: @ "1.1" forKey: @ "b2"];
    // true TRUE yes YES false FALSE no NO can recognize
    [obj setValue: @ "TRUE" forKey: @ "b3"];
    
    // turn to NSTring
    [obj setValue: @ "2014-10-24" forKey: @ "date1"];
    // do not know
    [obj setValue: @ "2014-10-24" forKey: @ "t1"];
    
    // in conclusion
    // Numeric string to numeric can be converted to numeric
    // class to class direct assignment without conversion 






Study on the type of self-active conversion 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.