November 2013
Beginner
325 pages
9h 47m
English
Categories let a programmer add methods to any existing class. For example, Apple gave us the class NSString. Apple does not share the source code to that class, but you can use a category to add new methods to it.
Create a new Foundation Command Line Tool called VowelCounter. Then create a new file that is an Objective-C category. Name the category BNRVowelCounting and make it a category on NSString.
Now open NSString+BNRVowelCounting.h and declare a method that you want to add to the NSString class:
#import <Foundation/Foundation.h> @interface NSString (BNRVowelCounting) - (int)bnr_vowelCount; @end
Now implement the method in NSString+BNRVowelCount.m:
#import "NSString+BNRVowelCounting.h" @implementation ...
Read now
Unlock full access