KVC中setValuesForKeysWithDictionary用法
来源:互联网 发布:手机解压缩软件zip 编辑:程序博客网 时间:2024/05/22 11:33
从字典映射到一个对象,这是KVC中的一个方法所提供的,这个方法就是 setValuesForKeysWithDictionary: ,非常好用,不需要你来一一的给对象赋值而直接从字典初始化即可,但用的不好会经常崩溃,本教程就来讨论这些使用的细节.
首先,先初始化一个字典,如下所示:
-------------------------------------------------------------------------------------
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
@"Y.X.", @"name",
@"26", @"age",
@"海淀区", @"address", nil];
-------------------------------------------------------------------------------------
创建PersonInfoModel,代码如下所示
-------------------------------------------------------------------------------------
#import <Foundation/Foundation.h>
@interface PersonInfoModel : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *age;
@property (nonatomic, strong) NSString *address;
@end
-------------------------------------------------------------------------------------
#import "PersonInfoModel.h"
@implementation PersonInfoModel
@end
-------------------------------------------------------------------------------------
测试后打印信息如下:
- KVC中setValuesForKeysWithDictionary用法
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:详解
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary
- KVC中setValuesForKeysWithDictionary:
- LeetCode Rotate List
- 使用第三方工具Xtrabackup进行MySQL备份
- #学习笔记#(22)常用CSS命名规则
- 网络设备常用协议总结三(锐捷命令)
- GitHub教程--上传项目四步法 GitBash命令行下使用方法
- KVC中setValuesForKeysWithDictionary用法
- Linux /UNIX 状态解释
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree
- 通过adb命令向Android模拟器中导入通讯录联系人
- cmake:让mingw(gcc)生成MSVC可用的dll(.lib)
- Using scikit-learn Pipelines and FeatureUnions
- NSNSURLSession详解
- EasyUI 1.3.6 DateBox添加清空按钮
- [POJ 2010]Moo University - Financial Aid[优先队列]