'Print Current Module Name in Swift

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?



Solution 1:[1]

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]) }
}

Solution 2:[2]

And yet another way to print the current module name... in Swift.

let module = String(String(reflecting: MY_SUBJECT.self).prefix { $0 != "." })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Alexander Algashev