<div dir="ltr"><div>I'm trying to override some decode parsers from KeyedDecodingContainer, but I getting a stranger ambiguous error. Is stranger for me, because I'm getting this message error only on <b>Int</b> and <b>Double</b> override parse.<br></div><div><br></div><div>I appreciate any help because I don't know why the Float parse works and Int got the error.</div><div><br></div><div>This is my code</div><div><div><br class="gmail-Apple-interchange-newline"><code></div><font face="monospace, monospace">import Foundation<br><br>public extension KeyedDecodingContainer {<br> <br> public func decode(_ type: Float.Type, forKey key: Key) throws -> Float {<br> guard let stringValue = try? self.decodeIfPresent(String.self, forKey: key) else {<br> return try self.decode(Float.self, forKey: key)<br> }<br><br> guard let floatValue = Float(stringValue!) else {<br> return try self.decode(Float.self, forKey: key)<br> }<br> <br> return floatValue<br> }<br> <br> public func decodeIfPresent(_ type: Float.Type, forKey key: Key) throws -> Float? {<br> guard let stringValue = try? self.decodeIfPresent(String.self, forKey: key) else {<br> return try self.decodeIfPresent(Float.self, forKey: key)<br> }<br> <br> guard let floatValue = Float(stringValue!) else {<br> return try self.decodeIfPresent(Float.self, forKey: key)<br> }<br> <br> return floatValue<br> }<br><br> public func decodeIfPresent(_ type: Int.Type, forKey key: Key) throws -> Int? {<br> guard let stringValue = try? self.decodeIfPresent(String.self, forKey: key) else {<br> return try self.decodeIfPresent(Int.self, forKey: key)<br> }<br><br> guard let integerValue = Int(stringValue!) else {<br> return try self.decodeIfPresent(Int.self, forKey: key)<br> }<br> <br> return integerValue<br> } <br>}</font><div></code></div></div><div><br></div><div>... and I got this error on compilation.</div><div><br></div><div><error></div><div><p class="gmail-p1"><font face="monospace, monospace"><unknown>:0: error: ambiguous use of 'decodeIfPresent(_:forKey:)'<br><br>Swift.KeyedDecodingContainer:180:17: note: found this candidate<br><br> public func decodeIfPresent(_ type: Int.Type, forKey key: KeyedDecodingContainer.Key) throws -> Int?<br><br> ^<br><br>Pimenta.KeyedDecodingContainer<K>:4:17: note: found this candidate<br><br> public func decodeIfPresent(_ type: Int.Type, forKey key: KeyedDecodingContainer.Key) throws -> Int?</font></p><p class="gmail-p1"></error ><br></p></div><div><br></div><div><br></div>-- <br><div class="gmail_signature">"o animal satisfeito dorme". - Guimarães Rosa</div>
</div>