There was an error while loading. Please reload this page.
let metatype = type(of: variable)
func metatypeName<T>(of variable: T) -> String { let metatype = type(of: variable) return "\(metatype)" } protocol ProtocolThatIHATE {} struct StructThatILOVE: ProtocolThatIHATE {} let variable: ProtocolThatIHATE = StructThatILOVE() metatypeName(of: variable) // returns "ProtocolThatIHATE" ???!!?!
StructThatILOVE
func metatypeName<T>(of variable: T) -> String { let metatype = type(of: variable as Any) // casting to Any fixes the issue! return "\(metatype)" } metatypeName(of: variable) // returns "StructThatILOVE"! 🙌