From 6378f6058bf704ac10c144c5affa6118a61ddb90 Mon Sep 17 00:00:00 2001 From: Reed Es Date: Sat, 1 Apr 2023 12:59:19 -0600 Subject: [PATCH] Reworked gettingStarted and exercise/serving population --- Sources/Entities/MServing.swift | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Sources/Entities/MServing.swift b/Sources/Entities/MServing.swift index 976c9cc..e030d36 100644 --- a/Sources/Entities/MServing.swift +++ b/Sources/Entities/MServing.swift @@ -46,13 +46,13 @@ public extension MServing { presets.forEach { preset in userOrder += 1 - _ = MServing.create(context, - category: category, - userOrder: userOrder, - name: preset.text, - createdAt: createdAt) + let serving = MServing.create(context, + category: category, + userOrder: userOrder, + name: preset.text, + createdAt: createdAt) - // try task.replaceFields(context, from: preset) + serving.populate(from: preset) } } } @@ -72,3 +72,11 @@ public extension MServing { return Int(Float(calories) * lastIntensity) } } + +public extension MServing { + func populate(from preset: ServingPreset) { + volume_mL = Float(preset.volume_mL ?? 0) + weight_g = Float(preset.weight_g ?? 0) + calories = Int16(preset.calories) + } +}