Why doesn’t Swift call my overloaded method with a more specific type?
问题 I use Decodable to decode a simple struct from JSON. This works by conforming to a Decodable protocol: extension BackendServerID: Decodable { static func decode(_ json: Any) throws -> BackendServerID { return try BackendServerID( id: json => "id", name: json => "name" ) } } I’d like to be able to call decode with a String , though, so I have added an extension: extension Decodable { static func decode(_ string: String) throws -> Self { let jsonData = string.data(using: .utf8)! let jsonObject