KVC

3153 단어 VC
//  UserModel.h

//  KVC

//

//  Created by     on 15/7/20.

//  Copyright (c) 2015     . All rights reserved.

//



#import <Foundation/Foundation.h>



@interface UserModel : NSObject



@property (nonatomic,strong)NSString * userName;



@end



//  UserModel.m

//  KVC

//

//  Created by     on 15/7/20.

//  Copyright (c) 2015     . All rights reserved.

//



#import "UserModel.h"



@implementation UserModel



@end





//  StudentModel.h

//  KVC

//

//  Created by     on 15/7/20.

//  Copyright (c) 2015     . All rights reserved.

//



#import <Foundation/Foundation.h>



@interface StudentModel : NSObject



@property (nonatomic,strong)NSString * studentName;

@property (nonatomic,strong)NSString * sex;

/*........*/

@end





//  StudentModel.m

//  KVC

//

//  Created by     on 15/7/20.

//  Copyright (c) 2015     . All rights reserved.

//



#import "StudentModel.h"



@implementation StudentModel

{

    NSString *_age;

    NSArray *_friends;

}



-(void)setValue:(id)value forUndefinedKey:(NSString *)key{

    NSLog(@"UndefinedKey:%@",key);

}



@end


 
//  ViewController.h

//  KVC

//

//  Created by     on 15/7/20.

//  Copyright (c) 2015     . All rights reserved.

//



#import <UIKit/UIKit.h>



@interface ViewController : UIViewController





@end





//

//  ViewController.m

//  KVC

//

//  Created by     on 15/7/20.

//  Copyright (c) 2015     . All rights reserved.

//



#import "ViewController.h"

#import "UserModel.h"

#import "StudentModel.h"

@interface ViewController ()



@end



@implementation ViewController



- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

//    UserModel *userModel=[UserModel new];

    UserModel *userModel=[[UserModel alloc]init];

    userModel.userName=@"  ";

    NSLog(@"%@",userModel.userName);

    

    

    StudentModel *studentModel=[StudentModel new];

    //  :        setStudentName,        studentName,      ,   _studentName。

    [studentModel setValue:@"  " forKey:@"studentName"];

    NSLog(@"%@",[studentModel valueForKey:@"studentName"]);

    

    [studentModel setValue:@"18" forKey:@"age"];

    NSLog(@"%@",[studentModel valueForKey:@"age"]);

    

    

    [studentModel setValue:@[@"Baby",@"daheiniu",@"   "] forKey:@"friends"];

    NSLog(@"%@",[studentModel valueForKey:@"friends"]);

    

    NSDictionary *dic=[NSDictionary dictionaryWithObjects:@[@"18",@"  ",@" "] forKeys:@[@"age",@"studentName",@"seex"]];

    StudentModel *fanye=[StudentModel new];

    [fanye setValuesForKeysWithDictionary:dic];

    

    



    

//    [studentModel setValuesForKeysWithDictionary:];

    //

    

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end


좋은 웹페이지 즐겨찾기