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.
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!
More and more views will be included. As of today, workout views are implemented and a example widget is already done:
The main app struct Workout_CompanionApp
, contains a WorkoutManager
which is responsible of:
- Gathering
HealthKit
authorization - Gathering
HealthKit
data - Providing that data through
@Publisher
s 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.
- 🙌🏻 Say hi and add me on my LinkedIn
- 👾 Dare to challenge me @ Fifa or Warzone!
- 🐦 Connect on my Twitter
"It was a bright cold day in April, and the clocks were striking thirteen."