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
.
NSStringFromClass
Returns the name of a class as a string.
NSString * NSStringFromClass ( Class aClass );
You can do something like this
NSString *strClass = NSStringFromClass([viewController class]);
Use the function:
const char * class_getName(Class cls)
as
class_getName ([vc class]);
you can do some thing like the following when you instantiate your object:
[[NSClassFromString(@"className1") alloc] init];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With