Hey there,
I'm a beginner learning SwiftUI and working on my first app. I have a prototype working with placeholder data that I want to replace with Core Data.
It seems like the decisions I make now on the data model could have a big impact on the complexity and performance of my code later on. So I'm hoping folks with more experience would be willing to give me some feedback and direction.
The app is designed to help me maintain a daily meditation practice. It's a simple timer with a focus on keeping a streak alive. Here are screenshots of the relevant screens:
The data I need to display in the UI:
- Current streak (number of consecutive days a meditation session has been logged)
- Longest streak
- Total number of sessions
- Total days/hours/minutes spent meditating
- Progress toward the next milestone. Milestones are 7, 30, 60, 90, 180, 365 days
My current draft contains one entity with two attributes:
MeditationSession
entity
date
: Date type (set to Derived with now()
as the Expression)
duration
: Date type (set to Use Scaler Type so that it becomes TimeInterval
)
- Should I add any other attributes to make my life easier? ID etc?
The parts that seem straightforward:
- Get the Total Sessions by calculating the count of
MeditationSession
- Get the Total Days/Hours/Minutes by getting the sum of
duration
attribute
For streaks, I'm less confident about the best approach:
- Use the
date
attribute on MeditationSession
and calculate the consecutive days in a function? This seems pretty complicated for someone brand new to programming. Any APIs that I should look at using here to make my life easier?
- Should streaks be added to the model?
Milestones, even less confident:
- Do I need another entity in the model for this with boolean attributes for each milestone?
Many thanks in advance for any input you can provide!