Calling NSStringFromClass on a Swift Class in Objective-C returns module mangled name

前端 未结 7 773
遇见更好的自我
遇见更好的自我 2021-02-07 07:53

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

7条回答
  •  有刺的猬
    2021-02-07 08:31

    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
    

提交回复
热议问题