OnboardingKit helps you create onboarding expericences like hints and tutorials in Swift
and SwiftUI
.
The result can look like this, or completely different:
OnboardingKit has different onboarding types. Standard onboardings are shown right away, and only once, while other types can require multiple presentation attempts, a certain number of "incorrect" actions, etc. You can also combine different onboarding types to create new ones and reset the state of any onboarding to display it again.
OnboardingKit supports multiple users, so that each onboarding is unique to each user.
OnboardingKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/OnboardingKit.git
If you prefer to no have external dependencies, you can also just copy the source code into your app.
In OnboardingKit, an Onboarding
determines the state and behavior of an onboarding experience, while a Hint
is a short onboarding message and a Tutorial
is a page-based onboarding flow.
You can use various Onboarding
types to get different behaviors.
The code below shows how to use a standard onboarding to present a hint or tutorial:
import OnboardingKit
import SwiftUI
struct ContentView: View {
@State
private var isOnboardingPresented: Bool
private let hint = Hint(title: "Welcome!", text: "Welcome to this app.")
private let tutorial = LocalizedTutorial(id: "welcome")
var body: some View {
Text("Hello, world")
.onAppear(tryPresentOnboarding)
.sheet(isPresented: $isOnboardingPresented) {
TutorialPageView(tutorial: tutorial)
}
}
func tryPresentOnboarding() {
let onboarding = Onboarding(id: "welcome")
onboarding.tryPresent {
// Present the hint, for instance in a toast or a callout
// ...or, present the tutorial
isOnboardingPresented = true
// ...or do anything you want
}
}
}
As you can see in the code above, the onboarding holds the state and behavior, while the presentation block defines what should happen.
For more information, please see the online documentation and getting started guide.
The online documentation has more information, code examples, etc.
The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo
project.
You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.
Feel free to reach out if you have questions or if you want to contribute in any way:
- Website: danielsaidi.com
- Mastodon: @[email protected]
- Twitter: @danielsaidi
- E-mail: [email protected]
OnboardingKit is available under the MIT license. See the LICENSE file for more info.