How can I print the module name for a class in swift?
self.dynamicType
prints only the class name without the module. How can I print the module?
For the not-so-pretty but currently working way, try:
let object = NSStringFromClass(MyClass) as NSString
let module = object.componentsSeparatedByString(".").first!
This doesn't seem to work for Foundation/UIKit etc objects though
Here is a different solution
// "To parse a #fileID expression, read the module name as the text before the first slash (/) and the filename as the text after the last slash"
func moduleName(fileId: String = #fileID) -> String? {
fileId.firstIndex(of: "/").flatMap { String(fileId[fileId.startIndex ..< $0]) }
}
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