1

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 ?

Phil
  • 2,995
  • 6
  • 40
  • 67
  • You mean create a new class at runtime or get the `Class` of an existing class? –  Jun 08 '12 at 23:37

2 Answers2

2

Try:

id object = [[NSClassFromString(@"NameofClass") alloc] init];

from this thread:

Create objective-c class instance by name?

Community
  • 1
  • 1
podperson
  • 2,284
  • 2
  • 24
  • 24
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