I am aware of this question regarding how we can get a readable class name of an objective-c class in Swift.
What I want to achieve is getting the readable class name of
The reason you get "Bar.Foo"
is because swift is a namespace language. I'm assuming the application you were running this in was named Bar. Hence you may get your class name using the following:
let nameSpaceClassName = NSStringFromClass(Foo)
let className = nameSpaceClassName.componentsSeparatedByString(".").last! as String
Working solution for this in Swift 2.1 is
String(MyClass)
In objective-c your best option is:
NSString *yourCellName = NSStringFromClass([yourCell class]).pathExtension;
On the latest Swift below worked for me:
NSStringFromClass(type(of: yourClass!.self))
Try it with Swift 2.0:
self.description().componentsSeparatedByString(".").last!
Swift 5.1 solution for NSStringFromClass
If you want the string description of a class name (say CustomTableViewCell
) use:
String(describing: CustomTableViewCell.self)