Is there a way I can get/create a class in objective-c by using a String, like how I Can use getDefinitionByName in AS3 ?
Asked
Active
Viewed 168 times
1
-
You mean create a new class at runtime or get the `Class` of an existing class? – Jun 08 '12 at 23:37
2 Answers
2
Try:
id object = [[NSClassFromString(@"NameofClass") alloc] init];
from this thread:
0
I think you're looking for NSClassFromString. It should be used as such (I borrowed this code from this answer; the code is from Dave DeLong):
Class dictionaryClass = NSClassFromString(@"NSMutableDictionary");
id object = [[dictionaryClass alloc] init];
[object setObject:@"Foo" forKey:@"Bar"];

Community
- 1
- 1

eric.mitchell
- 8,817
- 12
- 54
- 92