Application Onboarding
I have spent a lot of the last week thinking a lot about the best way to onboard someone to may application. It is such a simple app that I just could not figure out
In the end, I decided to just keep it simple. On my Routines tab I added a view that displays a giant plus sign to add your first routine.
The next thing that I wanted to do was make the routine tab the default if there are no routines set up. To do this, I added a count function to my dataController so that I can quickly get the count of records for anything I have in CoreData.
1
2
3
func count<T>(for fetchRequest: NSFetchRequest<T>) -> Int {
(try? container.viewContext.count(for: fetchRequest)) ?? 0
}
Then I wrote a function that can quickly check if any routines exist, and if not set the tab to .routines
.
1
2
3
4
5
6
func checkForRoutines() {
let count = dataController.count(for: Routine.fetchRequest())
if count == 0 {
selectedTab = .routines
}
}
Finally, I just add it to the .onAppear
of my TabView.
1
2
3
.onAppear {
checkForRoutines()
}