I am trying to create an instance of a type based on another type passed to a method. I find that NSClassFromStringworks just fine if used with a string literal, as in
id instance = [[NSClassFromString(@"TheNameOfTheClassIWant") alloc] init];
but if I build a line with something like
NSString *inClassName = [[protoInstance class] description];
NSString *outClassName = [inClassName stringByAppendingFormat:@"IWant"];
id instance = [[NSClassFromString(outClassName) alloc] init];
what instance- nil. Does it work NSClassFromStringonly with literals? Does something happen at compile time to get the job done NSClassFromString?
source
share