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

Manual subsets of NSKeyValueCoding behavior


The NSKeyValueCoding protocol acts in different ways while looking up for methods and instance variables. In the first case, it will look up for the method's selector's name, while in the last, it will look up for the instance variable's name.

This can be done manually, as we can see in the following samples:

// Manual implementation of KVC setter for method.
NSString *mySetterString = [@"set" stringByAppendingString:[myKeyString capitalizedString]];
[myObject performSelector:NSSelectorFromString(mySetterString) withObject:myValue];

// Manual implementation of KVC setter for instance variable.
object_setInstanceVariable(myObject, myKeyString, myValue);

Since KVC can look up for setters and getters automatically, you might only be required to use the preceding approach by creating your own lookup path if you want to avoid NSKeyValueCoding to find specified or ordinary methods and instance variables.

Advantages of creating your own lookup path

To avoid...