Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get class from NSString?

for example, I have

NSString *myClass = @"RootViewController"

How do I get class from NSString?

like image 770
Voloda2 Avatar asked Sep 21 '12 18:09

Voloda2


People also ask

What is a NSString?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.

What is NSString in Objective C?

(NSString *) is simply the type of the argument - a string object, which is the NSString class in Cocoa. In Objective-C you're always dealing with object references (pointers), so the "*" indicates that the argument is a reference to an NSString object.


1 Answers

Try this

 id obj= [[NSClassFromString(@"RootViewController") alloc] init];
like image 111
NeverBe Avatar answered Sep 28 '22 09:09

NeverBe