Пример наследования:
#import <Foundation/Foundation.h> @interface MyClass : NSObject -(NSString *)description; @end @implementation MyClass -(NSString *)description { return @"MyClass"; } @end int main(int argc, const char * argv[]) { @autoreleasepool { MyClass *my = [[MyClass alloc] init]; NSLog(@"%@", my); } return 0; }
Пример категории:
#import <Foundation/Foundation.h> @interface NSString(MyClass) -(NSString *)removeDigits; @end @implementation NSString(MyClass) -(NSString *)removeDigits { NSCharacterSet *theDigits = [NSCharacterSet decimalDigitCharacterSet]; return [self stringByTrimmingCharactersInSet:theDigits]; } @end int main(int argc, const char * argv[]) { @autoreleasepool { NSString *my = [[NSString alloc] init]; my = @"123test456"; NSLog(@"%@", [my removeDigits]); } return 0; }