Europe/Berlin
Posts

Creating a Swift App to Track Vitamin D production

February 15, 2025
My journey with Swift and SwiftUI started with a simple goal: develop an app that helps users understand their daily vitamin D exposure while also giving me hands-on experience with Apple’s modern development tools. After having been recommended an app with the same goal which turned out to be complete garbage, I've asked myself, "Why not just do it myself?". As it turns out there was no other app whatsoever that did this simple task. I was surprised by how easily and swiftly Swift’s modern syntax and SwiftUI’s declarative framework allowed me to build an intuitive user interface. I spent countless hours experimenting with view modifiers, state management, and integrating system APIs. This project served as a perfect playground for:
  • Understanding Data Flow: How state changes can drive UI updates.
  • Experimenting with Layouts: Using SwiftUI’s stacks and grids to design a clean, user-friendly interface.
  • API Integration: Exploring how to pull real-time data, such as weather and UV index, to estimate vitamin D synthesis.
The app is designed with simplicity in mind. On opening the app, users are greeted with a one-time onboarding to set presets, allow integration of HealthKit and access to location services before being redirected to a clean dashboard that displays key information:
  • Sunlight Exposure Tracker: Users can log the amount of time spent outdoors. The app then uses this data alongside local UV index information to estimate the vitamin D produced.
  • Health Tips & Reminders: Based on user activity and location, the app offers suggestions for optimal times to soak up the sun and safe exposure practices.
  • Visual Data Representation: Intuitive graphs and charts help users visualize their vitamin D levels over time, making it easier to understand trends and adjust habits.
But most importantly, once the user has entered information such as Fitzpatrick skin type, sunscreen use, and his usual clothing to detemine the percentage of skin covered, there is next to no manual input required to decrease friction. By implenting HealthKit the calculations become even more precise, for example through the use of the "time spent outdoors" value that the Apple Watch can estimate. For users without it, I have written my own algorithms that correlate various data points to automatically determine when a user could be outdoors. To improve accuracy, the user can of course confirm or change the data that was automatically recognized, such as changing the time spent outdoors, clothing worn for the day, etc. My main goal was achieved as I now have a solid understanding of Swift and SwiftUI. However, some potential future features might include:
  • Personalized Recommendations: Utilizing machine learning to offer custom tips based on user habits.
  • Cross-platform development: Expanding the app to other platforms such as iPadOS, or even Android.
  • Update Vitamin D synthesis algorithms: Refining calculations with the latest research insights.