zoukankan      html  css  js  c++  java
  • KVC

    //  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
    
  • 相关阅读:
    python和搜索
    Flask---ajax(jquery)交互
    Flask--修改默认的static文件夹的方法
    Flask设计带认证token的RESTful API接口[翻译]
    Python 和 Flask实现RESTful services
    等差数列偶数被除2删除后的恢复问题(2018小马智行秋招计算机视觉第三道编程题)
    Leetcode 140 单词拆分II: 字符串s在字典wordDict中有多少种拆分方法。
    LeetCode 139 单词拆分:字符串s能否分割为字符串数组words(wordDict)中字符串的组合?(某未来公司面试题目)
    ROS时间概念总结:ros::Time、ros::Duration、定时器ros::Timer&ros::Rate
    ++i、i++、i+=1、i=i+1的区别
  • 原文地址:https://www.cnblogs.com/0515offer/p/4665452.html
Copyright © 2011-2022 走看看