ios kvc

//
//  KVCoding.m
//  kvc
//
//  Created by mac on 14-10-21.
//  Copyright (c) 2014年 liuli. All rights reserved.
//

#import "KVCoding.h"

@implementation KVCoding

@synthesize name;
@synthesize pass;
@synthesize birth;

-(void) setValue:(id)value forUndefinedKey:(NSString *)key{
    NSLog(@"the key [%@] not exist and you value is [%@]",key,value);
}
-(void) setNilValueForKey:(NSString *)key{
    NSLog(@"you value for key [%@]is nil ",key);
}
@end
=============================

//
//  KVCoding.h
//  kvc
//
//  Created by mac on 14-10-21.
//  Copyright (c) 2014年 liuli. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface KVCoding : NSObject

@property (nonatomic,copy) NSString* name;
@property (nonatomic,copy) NSString* pass;
@property (nonatomic) int birth;

@end

============================

//测试 KVC
        KVCoding* kvc = [[KVCoding alloc] init];
        [kvc setValue:@"liuli" forKey:@"name"];
        [kvc setValue:@"472732787" forKey:@"ww"];
        [kvc setValue:nil forKey:@"birth"];
  NSLog(@"name:%@",[kvc valueForKey:@"name"]);

你可能感兴趣的:(ios)