kvc-Key value encoding

Source: Internet
Author: User

KVC is a Key , value , Coding the abbreviation, that is, the key value encoding. In IOS , property information for an object can be accessed indirectly through the name of the class's property (key).

build a project to create a Zzperson class, which has two properties, name and the Address .

ZzPerson.h: #import <Foundation/Foundation.h> @interface zzperson:nsobject{        nsstring * name,address;    } @endViewController. h: The Zzperson class header file is introduced in the ViewController.h file, Viewcontroller has a property of the Zzperson type Sam. #import <UIKit/UIKit.h> #import "ZzPerson.h" @interface viewcontroller:uiviewcontroller@property (Nonatomic, Retain) Zzperson * SAM; @endViewController. M: #import "ViewController.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload {        [super viewdidload];        Create Zzperson object Sam        _sam=[[zzperson Alloc]init];        Set object Sam information via Key,value        [_sam setvalue:@ "Tangled Lun" forkey:@ "name"];        [_sam setvalue:@ "" forkey:@ "Address"];        Information about the SAM object is accessed through the person's properties.        NSLog (@ "%@", [_sam valueforkey:@ "name"]);        NSLog (@ "%@", [_sam valueforkey:@ "Address"]);    

A Class ( Zzperson ) of the object ( Sam ) by SetValue : Forkey statement to set the information for an object property, where Key is the class ( Zzperson ) is also the property of the object ( Sam ) of the Zodiac, where the Key respectively is name and the Address , through Key to set their information. The Valueforkey is then called by the object : The statement can access The property information corresponding to the key.


kvc-Key value encoding

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.