问题
I implemented an extension to NSObject to get the dynamic type of my objects:
extension NSObject {
var dynamic_type : String {
get {
return String(describing: type(of: self))
}
}
}
This works perfectly for public classes.
In a class called InitialState dynamic_type would be "InitialState" (this is what I want) But as soon as I change the class to private or fileprivate it is something like "(InitialState in _AF5C6D4A3B423A6F0735A7740F802E5A)" (the parenthesis are also returned)
Why is this and what does the part after "in" mean? How can I get the plain class name for every type of class? (public, private, fileprivate)
I know that I could simply parse the string to get the plain class name but I want to understand what exactly happens and if I maybe am doing it wrong.
来源:https://stackoverflow.com/questions/48306011/swift-4-typeof-self-differs-when-using-private-fileprivate