以下实例基于Swift4,且在class, struct, enum中都可用:
 
 
class Foo {

    // 实例属性中指定明确的类名来获取名称
    var typeName: String {
        return String(describing: Foo.self)
    }

    // 实例属性中动态获取类名来获取名称
    var otherTypeName: String {
        let thisType = type(of: self)
        return String(describing: thisType)
    }

    // 类属性中直接获取名称
    static var typeName: String {
        return String(describing: self)
    }

}

Foo().typeName       // = "Foo"
Foo().otherTypeName  // = "Foo"
Foo.typeName         // = "Foo"