Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a view controller's class name as string

If I have a UIViewController subclass, how can I get the class name as string? I've tried doing [vc class], but this returns a Class object, not an NSString.

like image 932
xonegirlz Avatar asked Jun 04 '12 22:06

xonegirlz


4 Answers

NSStringFromClass

Returns the name of a class as a string.

NSString * NSStringFromClass (  
    Class aClass  
);
like image 148
3 revs, 2 users 70% Avatar answered Nov 16 '22 17:11

3 revs, 2 users 70%


You can do something like this

NSString *strClass = NSStringFromClass([viewController class]);
like image 23
Hardik Darji Avatar answered Nov 16 '22 18:11

Hardik Darji


Use the function:

const char * class_getName(Class cls)

as

class_getName ([vc class]);
like image 4
GoZoner Avatar answered Nov 16 '22 17:11

GoZoner


you can do some thing like the following when you instantiate your object:

[[NSClassFromString(@"className1") alloc] init];
like image 4
shebelaw Avatar answered Nov 16 '22 18:11

shebelaw