June 2011
Intermediate to advanced
590 pages
19h 31m
English
In Objective-C, classes have instance and class methods. These define the behavior of a class and its instances. Sometimes, you are using a class and you really wish “it just had a method to do this cool thing I want to do.” You’re in luck. You can add methods to an existing class by creating a category for that class.
The syntax for a category is not at all scary like blocks; in fact, it’s something you’ve already used before. You will create a category for UIColor that has two new methods that an instance of UIColor will respond to. Create a new NSObject subclass. Name it UIColor+Extract.m. In UIColor+Extract.h, replace all of the code with the following:
#import <Foundation/Foundation.h> #import ...
Read now
Unlock full access