Avatar ·

How to get the class name of an object as a string in Swift?

Hello everyone! I just started learning Swift and ran into a problem. I need to get the class name of an object as a string to use it, for example, for logging or debugging. In Objective-C, I simply used `NSStringFromClass([myObject class])`, but in Swift this doesn't work the same way. I tried different approaches, but none give the desired result. For example: ```swift class MyClass { var name: String = "Test" } let obj = MyClass() print(obj.class) // Error: Value of type 'MyClass' has no member 'class' ``` I also tried `type(of: obj)`, but this returns the type, not a string. I need exactly the string representation, for example "MyClass". How can I do this? Is there a built-in method or do I need to write my own implementation? Thanks in advance for your help!