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

Maximum flexibility and handling unusual keys/values


After you learned so many ways to use key-value coding, there is still a very important way of implementation if you are looking for more flexibility while handling unusual keys/values. Just do it yourself. The final approach to key-value coding is to handle the implementation yourself.

Create a getter and setter method, and inside of each method properly returning and setting the values on a dictionary owned by the object might be the easiest way to do it.

We can check out this approach in the following sample code:

/*
//------------------------------
  We create the method called "setCollectionValue:forKey:"
//------------------------------
*/

- (void)setCollectionValue:(id)value forKey:(NSString *)key
{
      /*
     //------------------------------
	 Here we set the value for key in a dictionary owned by the object.
     //------------------------------
     */

      [collectionDictionary setObject:value forKey:key];
}
 /*
//------...