"Extension Methods" in Objective-C

objective-c

Solution

This is done by the use of categories. You can use categories to add methods to any class. See: https://developer.apple.com/library/mac/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html#//apple_ref/doc/uid/TP40011210-CH6-SW1

Example:

#import "ClassName.h"

@interface ClassName ( CategoryName )
// method declarations
@end

Problem

How do I write my own "extension method" in objective-c? http://code.google.com/p/json-framework/ This library does it and it works like this. ``` NSString *myString = ...; id myResult = [myString JSONValue]; ``` where the `myResult` returns an `NSDictionary` or `NSArray`. What are these called? How do I write my own?

Original source