Better handling of Nutriments
This commit is contained in:
15
Sources/OpenFoodFacts/Schemas/Images.swift
Normal file
15
Sources/OpenFoodFacts/Schemas/Images.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
import Foundation
|
||||
|
||||
public struct Images: Codable {
|
||||
public var otherData: [String: Data] = [:]
|
||||
|
||||
mutating func setDetail<T: Encodable>(key: String, value: T) throws {
|
||||
let encodedValue = try JSONEncoder().encode(value)
|
||||
otherData[key] = encodedValue
|
||||
}
|
||||
|
||||
func getDetail<T: Decodable>(key: String, type: T.Type) throws -> T? {
|
||||
guard let data = otherData[key] else { return nil }
|
||||
return try JSONDecoder().decode(type, from: data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user