swiftui-widgets-fitness

Example project with SwiftUI, Combine and Widgets, using Apple Fitness app UI as the base

ℹ️ What is this project?

This project will try to help you understand the basics behind SwiftUI and Combine (+ some Widgets and HealthKit!).
It contains different branches that will incrementally add functionality, from the most basic state, to the addition of widgets and more configuration.

? Why did I started this project?

I love Apple Fitness workout views but sadly (as today), those same views are not offered as widgets for the home screen. So I am replicating those ones, and adding the widget-capability myself. By open sourcing it, I thought It could be a great example for other developers to see how to deploy a basic structure of SwiftUI-Combine + Widgets and HealthKit with clear and concise code.
Feel free to open PR or issues to improve it!

?️‍♀️ The workout widgets

More and more views will be included. As of today, workout views are implemented and a example widget is already done:

App demo

? High level design

The main app struct Workout_CompanionApp, contains a WorkoutManager which is responsible of:

  • Gathering HealthKit authorization
  • Gathering HealthKit data
  • Providing that data through @Publishers into anyone observing

The main app inits this WorkoutManager as a @StateObject property that will be injected via environmentObject into the main view tree.

The main view will use specific publishers from the WorkoutManager to feed specific views/widgets down the UI tree. This publishers will emit specifc ViewModels for each view that needs to consume them.

117647482-eaeafc00-b184-11eb-8de2-b984425525c4

GitHub

https://github.com/marioeguiluz/swiftui-widgets-fitness