In order for a class to be considered KVC compliant for a specific property, it must implement the methods required for valueForKey: and setValue:forKey: to work for that property.
Attribute and To-One Relationship Compliance
Indexed To-Many Relationship Compliance
Unordered To-Many Relationship Compliance
For properties that are an attribute or a to-one relationship, this requires that:
Your class implements a method named -<key>, -is<Key>, or has an instance variable <key> or _<key>.
If the property is mutable, then it should also implement -set<Key>:.
Your implementation of the -set<Key>: method should not perform validation.
Your class should implement -validate<Key>:error: if validation is appropriate for the key.
For indexed to-many relationships, KVC compliance requires that your class:
Implements method named -<key> that returns an array.
Or has an array instance variable named <key> or _<key>.
Or implements the method -countOf<Key> and one or both of -objectIn<Key>AtIndex: or -<key>AtIndexes:.
Optionally, you can also implement -get<Key>:range: to improve performance.
For a indexed ordered to-many relationship, KVC compliance requires that your class also:
Implement one or both of the methods -insertObject:in<Key>AtIndex: or -insert<Key>:atIndexes:.
Implement one or both of the methods -removeObjectFrom<Key>AtIndex: or -remove<Key>AtIndexes:.
Optionally, you can also implement -replaceObjectIn<Key>AtIndex:withObject: or -replace<Key>AtIndexes:with<Key>: to improve performance.
For unordered to-many relationships, KVC compliance requires that your class:
Implements method named -<key> that returns a set.
Or has an set instance variable named <key> or _<key>.
Or implements the methods -countOf<Key>, -enumeratorOf<Key>, and -memberOf<Key>:.
For a mutable unordered to-many relationship, KVC compliance requires that your class also:
Implement one or both of the methods -add<Key>Object: or -add<Key>:.
Implement one or both of the methods -remove<Key>Object: or -remove<Key>:.
Optionally, you can also implement -intersect<Key>: and -set<Key>: to improve performance.
© 2003, 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-02-04)