Journey of Two Weeks: Developing an iOS App using SwiftUI and HealthKit

Sarah Octavia
6 min readJun 3, 2023

--

In today’s fast-paced world, maintaining a healthy lifestyle is more important than ever. The right amount of hydration is essential to wellbeing. Water plays a vital role in our overall health, affecting our energy levels, digestion, cognitive function, and more. Staying well hydrated is a must for achieving optimal health and wellness. However, in the hustle and bustle of daily life, it is easy to forget about our water consumption. Keeping track of how much water you drink is crucial for everyone, especially for those who have certain health conditions or have special hydration requirements.

This is where I came up with the idea of creating an iOS mobile app for helping people who are concerned about their water intake and want to keep track of it on a regular basis. My goal in developing this app is to hone my coding and design skills while also exploring  Apple’s framework, particularly HealthKit. As this is my first time developing an iOS app on my own, I faced the challenge of determining which features to prioritize and which tasks to tackle first, especially given the limited two-week timeframe.

Introducing Watta — The app that will transform the way you monitor and enhance your day-to-day water consumption. Watta helps you stay hydrated and easily reach your health goals by adjusting your water intake to your body weight and length of exercise. Additionally, by serving as a constant reminder to you to keep track of it.

app logo with a text “Watta”

Through giving it the name Watta, which means water, I aim to create awareness and encourage mindfulness about water consumption. Furthermore, “Watta” conveys a sense of simplicity and accessibility. The name is short, catchy, and easy to remember, reflecting the app’s user-friendly interface and straightforward functionality. It emphasizes the app’s goal of making water tracking effortless and enjoyable, allowing users to stay hydrated and maintain a balanced lifestyle effortlessly.

How does this app work?

Watta will calculate your fluid needs based on your body weight. Watta will increase your fluid goal every 20 minutes of your exercise time to prevent dehydration. Monitoring your fluid intake progress can be a crucial step towards achieving your health goals. One way to do this is by manually adding your water intake. By doing so, you can keep track of how much water you are consuming throughout the day and ensure that you are meeting your daily hydration needs. This can be especially helpful if you are trying to increase your water intake or if you have a specific health condition that requires you to monitor your fluid intake. So, take control of your hydration and start tracking your water intake today! You will also receive a reminder to stay hydrated every two hours.

Here is the link to my prototype in Sketch

Let’s talk about the things I’ve learned while making this app :

  • HealthKit

HealthKit is an  Apple framework to access and share health and fitness data while maintaining the user’s privacy and control.

For this app, I use this framework to collect body weight and exercise duration data from the Health app. And also to store water data in the Health app. As I want to read and write data, I also learned how to request authorization from the user to access the Health app.

For further information about HealthKit, read the documentation here

  • Implement design patterns — MVVM

MVVM is a design pattern that helps you organize your code to make it easier to read, maintain, and extend. MVVM, as implied by its name, consists of three components.

  1. Model: An application’s model contains data and business logic. It contains domain-specific data structures, operations, and rules. The Model component retrieves, manipulates, and persists data without UI knowledge.
  2. View: View shows user interface elements and their layout. It controls user interactions and data presentation. The View in the MVVM pattern should be passive and not contain business logic. It displays and updates data directly from the ViewModel.
  3. ViewModel: The ViewModel bridges the View and Model. The View uses its data, commands, logic, and behaviors. The ViewModel transforms Model data into View-friendly form. It updates the Model and notifies the View of user interactions.

In this app, I’m trying to implement design pattern in my work so that it’s way easier to manage. Here’s how I do it in my project.

  • Water Wave Animation

If you’re interested in learning how to make your own water wave animation, check out this link for a step-by-step guide.

  • User Notifications

User Notifications is an  Apple framework to push user-facing notifications to the user’s device from a server or generate them locally from your app.

For this app, I use this framework to send a notification to the user to remind them to stay hydrated.

Watta reminder notification in iOS and WatchOS

For more information about user notifications, read the documentation here

And now let’s talk about why my code app isn’t quite what I want yet :

  1. Too many hard code!

There are still some hardcoded values in this app, and one of them has to do with the notifications. For instance, the frequency of water intake reminders is currently hardcoded to a fixed 2-hour interval, beginning at 8 a.m. and ending at 8 p.m. Unfortunately, this lack of flexibility means that users can’t change the time between reminders to fit their needs or schedules. To enhance the user experience, it would be helpful to add adjustable settings that let users set the reminder frequency based on how much water they want to drink and when they want to drink it.

2. Using UserDefaults to save the data

UserDefaults data is stored in the app’s sandbox directory as a property list, so users and other apps can modify it. Due to its inherent lack of security, UserDefaults is not suitable for storing sensitive information like medical records, health data, or personal details. However, in this app, UserDefaults is still being utilized.

Instead, use Keychain or encrypted databases for health data. These storage options encrypt and secure sensitive data.

It is critical to prioritize user privacy and follow best practices for handling and storing sensitive data, particularly when dealing with health-related data.

To sum up my learning journey, I can confidently say that it has been a valuable experience. As I continue to strive for excellence, I acknowledge that there is always room for improvement and that failure is an inevitable part of the journey. Creating the Watta app is a labor of love that leaves me exhausted but fulfilled ❤

Here is my Github for this project; if you’re interested and want to learn all the technologies that I’ve implemented in this project, feel free to read it and gain knowledge from it.
Additionally, any feedback is greatly appreciated! please hit me up here!

© 2023 Sarah Uli Octavia. All Rights Reserved.

--

--