美文网首页
KVC(key value coding)

KVC(key value coding)

作者: JaXz | 来源:发表于2016-04-23 14:18 被阅读63次

简介

KVC是一种可以直接通过字符串的名字(key)来访问类属性的机制。而不是通过调用Setter、Getter方法访问。

当使用KVO、Core Data、CocoaBindings、AppleScript(Mac支持)时,KVC是关键技术。


Set

setValue: forkey:// 只能给对象的直接属性赋值

setValue:forKeyPath: //可以给对象的间接属性赋值。多层赋值, 推荐使用


Get

valueForKey: //获取单个值

valueForKeyPath: //获取多层值

dictionaryWithValuesForKeys://模型转字典

获取数组中的对象:

运算符:


字典转模型

注意点:

1.如果想使用KVC进行字典转模型, 那么字典中的key必须和模型中的属性一模一样(个数 + 名称)否则会报错:this class is not key value coding-compliant for the key score.

2.如果使用KVC进行字典转模型, 只能对当前调用KVC方法的对象进行转换, 不能对它的属性的对象进行转换,意思就是说:对象中的对象无法转换,需要另行进行手动转换,再次处理

setValuesForKeysWithDictionary:

相关文章

  • KVC&KVO

    一.KVC 1.KVC即Key-value coding Key-value coding is a mechan...

  • delegate和notification区别,分别在什么情况下

    KVC(Key-Value-Coding)KVO(Key-Value-Observing)理解KVC与KVO(键-...

  • KVC & KVO

    一.什么是KVC KVC,key-value-coding,键值编码,即通过 key(属性名称)对 value(属...

  • iOS - 探索KVC及其原理

    KVC 全名:Key-value coding,中文简直编码。苹果对其定义如下: Key-value coding...

  • iOS中KVC及KVO的简单理解

    一、KVC及KVO的介绍 KVC:即Key-Value-Coding,用于键值编码。KVO:即Key-Value-...

  • KVC分析

    KVC是什么? kvc 是key value coding 的缩写,在ios中用于通过key,来获取value,即...

  • iOS开发 KVC与KVO

    KVC About Key-Value CodingKey-value coding is a mechanism...

  • KVC 和 KVO

    简介 KVC 英文 (Key-Value Coding) 和 (Key-Value Observing) 是 O...

  • KVO和KVC

    全称 KVO: Key-Value-Observer KVC: Key-Value-Coding KVO的使用 使...

  • 理解KVC&KVO

    一、Key Value Coding 协议 Key Value Coding是cocoa的一个基本组成部分。KVC...

网友评论

      本文标题:KVC(key value coding)

      本文链接:https://www.haomeiwen.com/subject/kuwxrttx.html