Book Image

Objective C Memory Management Essentials

Book Image

Objective C Memory Management Essentials

Overview of this book

Table of Contents (18 chapters)
Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

The NSKeyValueCoding protocol


The NSKeyValueCoding protocol is used in every sample code I've shown until now. I also have been calling it a protocol, but as I said earlier, it's an informal protocol, a NSObject category.

KVC is a mechanism that enables you to indirectly access an object's properties, using a "key" of strings to do it. To enable KVC, NSKeyValueCoding must be complied by your classes. Most of the time, you don't need to do anything in order to get it done because it's complied by NSObject.

To make a key-value coding compliant class for a certain property, the methods setValue:forKey: and valueForKey: must be implemented to work as expected.

Compliance of attributes and one-to-one relationships

You must ensure that your class has the following specification in case the of properties that are simply attributes or one-to-one relationships; an example would be [myObject setValue:myValue forKey:@"myProperty"];, which we saw earlier:

  • Have an instance variable called <key> or _...