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

Selectors as keys


Normally, KVC looks up for a property key and acts only after the property key is found. The other approach is about acting on an object's property in the lookup process. There is a lookup method in Objective-C core and its keys are used as selectors.

The following line of code is how you implement this lookup method:

objc_msgSend(myObject, mySetterSelector, myValue);

Note

This method is very similar to the manual implementation of the instance variable's setter, but instead of using the key to form a selector to do a look up, it uses the selector itself as the key.

Advantages of using selectors as keys

  • It's possible to get and set non-object data.

  • From all approaches that handles methods, this is the fastest one.

Disadvantages of using selectors as keys

  • You need different selectors for get and set

  • Since selectors are not objects, it's impossible to store directly in NSArray and NSDictionary. Instead, you can use NSValue or Core Foundation