Re: Abstracting a group of commonly named Selectors
Sandor Szatmari
Jeff,
toggle quoted message
Show quoted text
Works great! See my implementation below… The one thing I wasn’t sure about was the types array argument for class_addMethod() The fourth param… I used ‘i’ to specify the return type of integer. The return type is an enum. Wasn’t sure if there was a better choice This removed a ton of unnecessarily redundant code! -(id)init { self = [super init]; if ( self != nil ) { IMP parser_imp = class_getMethodImplementation([self class], @selector(parseStep) ); for ( SelectorStep *step in [self parseSteps] ) { SEL sel = step.selector; if ( [self respondsToSelector:sel] == NO ) class_addMethod( [self class], sel, parser_imp, "i@:" ); } } return self; } // -------------------------------------------- -(ParserStepStatus)parseStep { const char *selName = sel_getName(_cmd); NSString *table = [NSString stringWithCString:selName encoding:NSUTF8StringEncoding]; if ( [table isEqualToString:@"parseRoutePartitions"] ) NSLog( @"Stop" ); NSAssert1( [table hasPrefix:@"parse"], @"Selector must start with parse. Bad Selector: '%@'", table ); table = [[table substringFromIndex:5] snakeCase]; return [self parseStepByNameWithParams:[self stepDictForTableName:table]]; } Sandor On Jul 21, 2020, at 19:56, Sandor Szatmari via groups.io <admin.szatmari.net@...> wrote:
|
|