Objective C Extensions by Example
When we need to add private methods specific to a class, we can use extensions. A simple extension is shown below.
@interface EezySample:NSObject
@end
// Class extension
@interface EezySample()
// private method
- (void)sampleMethod;
@end
@implementation EezySample
- (void)sampleMethod{
NSLog(@"private method");
}
@end
int main(int argc, const char * argv[])
{
// Autoreleasepool used in main for automatic memory management.
@autoreleasepool {
EezySample *eezySample= [[EezySample alloc] init];
[eezySample sampleMethod];
}
return 0;
}