Making a protocol's property KVC compliant

落爺英雄遲暮 提交于 2019-12-12 01:55:10

问题


I'm using Xcode 6.1.1 and the iOS SDK 8.1

I have a class that is derived from NSObject, but its property is defined in a protocol (it is called phoneNumber, which I don't believe to be a problematic name). I'm getting the error message

this class is not key value coding-compliant for the key phoneNumber.

so I implemented the valueForKey: and setValue:ForKey: methods on my own and it fixed it. Is there a better way of doing making it KVC compliant?


回答1:


Auto property synthesis will not synthesize properties declared in protocols, you need synthesize it.(or create the getter and setter by hand).

In the class that implements the protocol add this line in the implementation file.

@synthesize phoneNumber = _phoneNumber;


来源:https://stackoverflow.com/questions/27835715/making-a-protocols-property-kvc-compliant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!