Objective-C Method Definition Internals

We’ve talked in a previous article about class definitions and we’ve looked at Objective C-class definition structures. They use an __objc_class structure which contains information with respect to the class’s super class, something called a meta class, a cache, a vTable, and a pointer to class data. We were working with a simple Printer class:
#import

@interface Printer : NSObject

@property NSString *str_to_print;

– (void) printMsg;
– (void) printString: (NSString*) message;

@end

@implementation Printer

– (void) printMsg {
printf(“%s\n", [self.str_to_print UTF8String]);
}

– (void) printString: (NSString*) message {
self.str_to_print = message;
[self printMsg];
}

@end

int main(int argc, const char * argv[]) {
@autoreleasepool {
Printer *printer = [[Printer alloc] init];
[printer printString: @"Hello World!"];
}
return 0;
}
Now a metaclass in Objective-C allows you to treat a class as an object, essentially. You can create static methods in Objective C, and the meta class is what allows you to do it. Class definitions can have associated methods and data elements, just like a class instance, and need are implememented in the same way as a result.

Link: https://dzone.com/articles/objective-c-method-definitions?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev