Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use NSKeyValueCoding protocol while designing data models?

I have been trying to create a data model class while following the NSKeyValueCoding protocol. I keep getting the following error: "Cannot find protocol declaration" And when I try to #import "NSKeyValueCoding.h" I get the file not found error.

Where can I find this protocol OR how else can it be implemented?

like image 978
Kushal Ashok Avatar asked Apr 16 '26 06:04

Kushal Ashok


1 Answers

NSKeyValueCoding is part of Foundation. So if you #import <Foundation/Foundation.h> you already included the header.

NSKeyValueCoding is an informal protocol. That means that classes do not explicitly conform to it. On the contrary: The protocol claims that the class it is declared upon, NSObject in this case, does understand all it's methods.

So: You cannot write a (NSObject derived) class in Cocoa that does not conform to KVC.

But: You can add non KVC-compliant properties to this class, for example by using funny names for accessors. It might make sense for an implementation to follow the rules for being KVC compliant or even KVO compliant.

like image 75
Nikolai Ruhe Avatar answered Apr 18 '26 18:04

Nikolai Ruhe