I am a somewhat competent Rubin programmer. Yesterday, I finally decided to try my hand at using the Apple Cocoa frameworks. Help me figure out the ObjC method?
I am trying to get around objc_allocateClassPair and objc_registerClassPair . My goal is to dynamically generate multiple classes, and then be able to use them like any other class. Does it work in Obj C?
Selecting and registering class A , I get a compilation error when I call [[A alloc] init]; (he says 'A' Undeclared ). I can only instantiate A using the objc_getClass runtime objc_getClass . Is there a way to tell the compiler about A and pass it messages, how would I NSString ? Compiler flag or something else?
I have 10 or so other classes ( B , C , ...), all with the same superclass. I want to report them directly to code ( [A classMethod] , [B classMethod] , ...) without the need for objc_getClass . Am I trying to be too dynamic here or just mess up my implementation? It looks something like this ...
NSString *name = @"test"; Class newClass = objc_allocateClassPair([NSString class], [name UTF8String], 0); objc_registerClassPair(newClass); id a = [[objc_getClass("A") alloc] init]; NSLog(@"new class: %@ superclass: %@", a, [a superclass]);
source share