Compliance Checklist
Follow the steps summarized in this section to ensure your objects are key-value coding compliant. See the previous sections for details.
Attribute and To-One Relationship Compliance
For each property that is an attribute or a to-one relationship:
Implement a method named
<key>oris<Key>, or create an instance variable<key>or_<key>. The compiler typically does this for you when it automatically synthesizes properties.If the property is mutable, implement the
set<Key>:method. The compiler typically does this for you when you allow it to automatically synthesize your properties.If the property is a scalar, override the
setNilValueForKey:method to gracefully handle the case where anilvalue is assigned to the scalar property.
Indexed To-Many Relationship Compliance
For each property that is an ordered, to-many relationship (such as an NSArray object):
Implement a method named
<key>that returns an array, or have an array instance variable named<key>or_<key>. The compiler typically does this for you when it automatically synthesizes properties.Alternatively, implement the method
countOf<Key>and one or both ofobjectIn<Key>AtIndex:and<key>AtIndexes:.Optionally, implement
get<Key>:range:to improve performance.
In addition, if the property is mutable:
Implement one or both of the methods
insertObject:in<Key>AtIndex:andinsert<Key>:atIndexes:.Implement one or both of the methods
removeObjectFrom<Key>AtIndex:andremove<Key>AtIndexes:.Optionally, implement
replaceObjectIn<Key>AtIndex:withObject:orreplace<Key>AtIndexes:with<Key>:to improve performance.
Unordered To-Many Relationship Compliance
For each property that is an unordered, to-many relationship (such as an NSSet object):
Implement the
<key>that returns a set, or have anNSSetinstance variable named<key>or_<key>. The compiler typically does this for you when it automatically synthesizes properties.Alternatively, implement the methods
countOf<Key>,enumeratorOf<Key>, andmemberOf<Key>:.
In addition, if the property is mutable:
Implement one or both of the methods
add<Key>Object:andadd<Key>:.Implement one or both of the methods
remove<Key>Object:andremove<Key>:.Optionally, implement
intersect<Key>:to improve performance.
Validation
Opt in to validation for properties that need it:
Implement the
validate<Key>:error:method, returning a boolean indicating the validity of the value, and a reference to an error object when appropriate.
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-10-27
