In Swift, we can no longer use "self.class".
I want to print own class name for description method in subclass of NSObject.
How can I print it? Or I should make new method for getting class name?
I checked the following question, but I couldn't get the answer.
How do I print the type or class of a variable in Swift?
How do you find out the type of an object (in Swift)?
import UIKit class PrintClassName: NSObject { override init() { super.init() println("\(self.dynamicType)") // Prints "(Metatype)" println("\(object_getClassName(self))"); // Prints "0x7b680910 (Pointer)" println("\(self.className)") // Compile error! println(PrintClassName.self) // Prints "(Metatype)" } }
2014.08.25 postscript
I checked the question.
Swift class introspection & generics
But println(PrintClassName.self)
prints "(Metatype)"
And I want to get class name without writing the class name on source code.
import Foundation class PrintClassName : NSObject { override init() { super.init() println(NSStringFromClass(self.dynamicType)) } }
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