Michael Grant

Michael Grant

Working with the garage door up: MetaboLog

A few weeks ago I finished Paul Hudson’s excellent 100 Days of SwiftUI course. The next step in getting hired as a developer and/or building an indie developer business while continuing to develop my skills is to start building an app or two.

Since I’m currently trying to lose some weight (so I can fit back into some really nice bespoke-tailored shirts that I’ve, ahem, outgrown), and I’ve only ever succeeded at that in the past via old-school calorie counting, I decided my first project would be an app I can use to log my weight against my food intake. I call it MetaboLog.

Tailored shirts
Motivation

Besides calories, I want to be able to track macronutrients (protein, fat, and carbohydrates) as well as, optionally, micronutrients such as vitamins and minerals. To minimize friction, I also want the flexibility to be able both to log known meals with a click and to analyze previously unrecorded dishes from their ingredients.

MetaboLog screenshot

I’ll be drawing the detailed nutritional data from the U.S. Department of Agriculture’s FoodData Central database. The data structure from its API — multiple APIs, actually — is quite a bit more complex than anything in a coding tutorial, but I suppose that’s the game I signed up to play.

As of right now I’m at a loss why the JSONDecoder can parse “lowercaseDescription”:“cheddar cheese” just fine, but fails to parse “servingSizeUnit”:“g” within the same chunk of JSON.

Update: the “servingSizeUnit” attribute doesn’t exist for every element in the JSON dataset, so it has to be decoded as an optional String? rather than a plain String. Ahhhhbviously!