views:

102

answers:

2

Hello,

How to load a class in Objective-C for iPhone application? I know tat Bundling concept is in MAC , but for iPhone can i use the same bundle concept to load a class?

A: 

What do you want to load? If you want to load a class from a nib you'd simply do something like:

YourClassName *classInstance = [[YourClassName alloc] initWithNibName:@"YourClassName" bundle:Nil];

Only some classes will implement the initWithNibName, such as UIViewControllers. You can also load a class from a nib from your bundle to an owner using the following:

[[NSBundle mainBundle] loadNibNamed:@"YourClassName" owner:self options:nil];
mjdth
Can i do this for developing an iPhone application also??
suse
Yes these are what I used in my iPhone application.
mjdth
I don't want to load it from nib, i have to load a class which is in Hashtable.
suse
A: 

I use the way as follows

    Class c = NSClassFromString( YourClassNameHere );


YourClass* ojectInstance = [c new];
Robin