Files
swift-openfoodfacts-sdk/Sources/OpenFoodFactsSDK/Extensions/KeyDecodingContainer+Helpers.swift
cdricms 043de16a16 Api v2
2025-12-06 16:33:17 +01:00

12 lines
296 B
Swift

extension KeyedDecodingContainer {
public func decodeFloatOrString(forKey key: Key) throws -> Float? {
if let floatVal = try? decode(Float.self, forKey: key) {
return floatVal
}
if let stringVal = try? decode(String.self, forKey: key) {
return Float(stringVal)
}
return nil
}
}