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 *Int* and *Double* override parse.
I appreciate any help because I don't know why the Float parse works and Int got the error. This is my code <code> import Foundation public extension KeyedDecodingContainer { public func decode(_ type: Float.Type, forKey key: Key) throws -> Float { guard let stringValue = try? self.decodeIfPresent(String.self, forKey: key) else { return try self.decode(Float.self, forKey: key) } guard let floatValue = Float(stringValue!) else { return try self.decode(Float.self, forKey: key) } return floatValue } public func decodeIfPresent(_ type: Float.Type, forKey key: Key) throws -> Float? { guard let stringValue = try? self.decodeIfPresent(String.self, forKey: key) else { return try self.decodeIfPresent(Float.self, forKey: key) } guard let floatValue = Float(stringValue!) else { return try self.decodeIfPresent(Float.self, forKey: key) } return floatValue } public func decodeIfPresent(_ type: Int.Type, forKey key: Key) throws -> Int? { guard let stringValue = try? self.decodeIfPresent(String.self, forKey: key) else { return try self.decodeIfPresent(Int.self, forKey: key) } guard let integerValue = Int(stringValue!) else { return try self.decodeIfPresent(Int.self, forKey: key) } return integerValue } } </code> ... and I got this error on compilation. <error> <unknown>:0: error: ambiguous use of 'decodeIfPresent(_:forKey:)' Swift.KeyedDecodingContainer:180:17: note: found this candidate public func decodeIfPresent(_ type: Int.Type, forKey key: KeyedDecodingContainer.Key) throws -> Int? ^ Pimenta.KeyedDecodingContainer<K>:4:17: note: found this candidate public func decodeIfPresent(_ type: Int.Type, forKey key: KeyedDecodingContainer.Key) throws -> Int? </error > -- "o animal satisfeito dorme". - GuimarĂ£es Rosa
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users