Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Introspection (reflection) is the act of exploring information about an object, often referred to as its metadata: the class of the object, the methods it implements, what properties it declares, the protocols (interfaces) it conforms to, and so on. The common questions ("What class is this object?," "Can I treat this object as a specific class?," and "Does this object implement a specific method?") are all easy to answer. This chapter will first tell you how to answer those common questions. It will then look into the deeper exploration of objects and classes.
This chapter will also explore Key-Value Coding, a technology closely related to introspection. Key-Value Coding, or KVC, allows you to access the properties of an object symbolically. As a trivial example, take a Person class that has NSString *name, Person *mother, and Person *father properties. KVC would allow you to get a person's name with the path @"name", and the name of their mother with the path @"mother.name". KVC isn't introspection; KVC won't tell you what properties an object implements. But it is so closely related to introspection that it's useful to understand what it can do for you. You might prefer to use KVC rather than perform your own introspection. You'll also want to know how to design your classes so that they work with KVC.