Sunday, May 01, 2011

Dynamic object creation

It seem that there are two ways to create object dynamically:
  1. Create from class name
  2. Create from class object
1. Create from class name
    Classes are objects as well in objective C. Hence a classs object can be created using class name. Once   
    a class object is created, an normal object can be created from the class object.
    eg.
               [[NSClassFromString(className) alloc] init...] 

2. Create from class object
    The class object can be created from the typical object by sending the class message to the object. Once
    the class object is created, the typical object can be created from the class object using the typical alloc
    and init way.
    eg.
                Class classForElement = [MyUserClass class];
                id newObject = [[classForElement alloc] init];
                MyUserClass* object = (MyUserClass *) id;