New app published: Karbs

A few months ago, I released a new iOS app called Karbs. It’s a carb-counting app designed for patients with diabetes.

Why would someone use an app to count carbohydrates?

My wife has been managing her diabetes since childhood. To keep track of the carbohydrates in her meals, including those cooked at home and ordered at restaurants, she used the Notes app from Apple.

She experimented with various applications that provided databases of nutritional information for common products, but her experience with them was not satisfactory. While some calculations were reasonably accurate, she found that her diabetes management was not effectively controlled due to the inaccuracies in the carbohydrate counting.

This prompted her to create her own list of carbohydrates, which would allow her to count them quickly and accurately. I wanted to assist her in this endeavor by developing an app specifically designed for this purpose.

What is carb counting, and why is it necessary?

You’ve probably seen a nutrition facts table on all the food you buy from the supermarket.

Carbohydrate counting involves determining the number of carbohydrates in a portion of food you intend to consume. For instance, if you consume the recommended portion (110g), it contains 23g of carbohydrates.

This calculation is crucial for individuals with type-1 diabetes because the amount of insulin they require for injection depends on two factors:

– The quantity of carbohydrates they plan to consume.

– The insulin dosage needed for 1g of carbohydrates.

Based on these two factors, type 1 diabetic patients can calculate the appropriate insulin dosage to administer before each meal. For example, if they consume 23g of carbohydrates and the recommended ratio is 2 IU per 10g, they would inject 2.3 IU of insulin.

While this calculation is straightforward and can be mentally performed by even children, it becomes more complex when considering varying ratios based on the time of day, menstrual cycles, and numerous other life factors such as stress or anxiety, as well as active insulin in the body.

In such cases, it is advisable for patients to use a Bolus Calculator to effectively manage their diabetes. This tool tracks different ratios and the active insulin levels in the body from previous meals. Ultimately, the most critical aspect is accurate carbohydrate counting.

Look and feel

I wanted to keep it as simple as possible, so I divided it into two tabs.

  • List of meals: Where you count the carbohydrates before eating.
  • List of food: Where you keep track of the nutritional facts for each food based on your regular consumption.

Users can simply add their food items in advance, and the counting process becomes straightforward. They can add items from their list, and the calculation will be displayed instantly.

Since my wife uses the Bolus Calculator from the mySugr app and importing data from Apple Health is a supported feature, I’ve also implemented data export.

Behind the scenes

I wanted to take this opportunity to create a new application from scratch and experiment with the new Observation tools introduced in version 1.7.0 of The Composable Architecture (TCA).

Implementing the app was incredibly straightforward. I only needed to create SwiftUI views and reducers for meals, food lists, meal counting, and item details. The integration of the Observation framework into the TCA library made the data bindings between the views and reducers seem like magic.

The most challenging part was persisting the data. I opted to store it in a simple file within the app’s sandbox.

One of the significant advantages of using TCA was that all data modeling was implemented using structs. This allowed me to provide users with the flexibility to modify the carbohydrate content of a food item without affecting the calculations for previous meals, including the same food item. For instance, if a user decides to purchase it from a different supermarket and the nutrition facts are slightly different, they can adjust the carbohydrate content without impacting the meal calculations.

The Composable Architecture is an exceptional implementation of the unidirectional data flow paradigm, elevating SwiftUI apps to new heights. It took me just four days to develop and publish my app, including creating a promotional website and professional AppStore screenshots, which I’ll delve into in a separate article.

Cristian Ortega
Cristian Ortega
I’m an iOS developer based in Barcelona, Spain. I'm passionate about crafting intuitive mobile experiences. On this page, I share insights and lessons from my professional journey to inspire fellow developers