本文介绍了为什么我的对象不是键值编码兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用键值编码在我的对象上设置值:
[engine setValue:[NSNumber numberWithInt: horsePower]
forKey:@horsePower];
导致错误:
[< Slant6 0x7fbc61c15c40> setValue:forUndefinedKey:]:这个类不是键值编码符合关键horsePower。
我需要做什么来使引擎
确认引擎
属于实现 horsePower 属性,和/或具有 horsePower 实例变量,和/或手动实现 setHorsePower:和 horsePower 方法。您尝试设置 horsePower 键的值,但引擎的类没有正确实现一种方法设置 horsePower 键。
Trying to use key-value coding to set a value on my object:
[engine setValue:[NSNumber numberWithInt:horsePower] forKey:@"horsePower"];
Causes an error:
[<Slant6 0x7fbc61c15c40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key horsePower.
What do I need to do to make engine key value coding-compliant?
解决方案
Make sure whatever class engine belongs to implements a horsePower property, and/or has a horsePower instance variable, and/or manually implements setHorsePower: and horsePower methods.
You are getting the error because you're trying to set the value of the horsePower key but engine's class does not properly implement a way to set the horsePower key.
这篇关于为什么我的对象不是键值编码兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!