5

how to dynamically load a class in Objective-C? As per my need, class name will be in a text file, which i need to read it, and then load the class dynamically ...

This code is loading a class in Java... I want the same functionality to be done in Objective-C...

public class MainClass {

  public static void main(String[] args){

    ClassLoader classLoader = MainClass.class.getClassLoader();

    try {
        Class aClass = classLoader.loadClass("com.jenkov.MyClass");
        System.out.println("aClass.getName() = " + aClass.getName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

}

which function in Objective-C is used instead of loadClass() in Java?

suse
  • 10,503
  • 23
  • 79
  • 113
  • duplicate: http://stackoverflow.com/questions/2175547/objective-c-dynamic-object-creation/2175616 – Vladimir Feb 04 '10 at 10:27
  • not a duplicate the other question asks how to create a instance from a class already loaded - this asks how to load from disk – mmmmmm Feb 04 '10 at 10:35
  • hey.. my main point here is, how to load a class dynamically inObjective-C?? – suse Feb 04 '10 at 10:43

1 Answers1

8

You can start reading the Bundle Programming Guide, especially the Loading Objective-C Classes section. You will find all the information regarding discovery and dynamic code loading (both functions and classes).

Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81