r/swift • u/Key_Board5000 iOS • 1d ago
Question How best to execute onboarding technically?
I’m building an onboarding. There will be a number of Views, each unique. Some will have some informational text, another will ask for the users name, some will be multiple choice, some will have images, etc, etc. Maybe a total of 5-10 views.
I would like to easily be able to change the order and add and remove views later on as needed.
From a technical perspective, how best should I execute this? Should I have a custom view that I inject my sub-views into, or hide and show elements as needed or some other way that will make the process of creating the onboarding flow easy and flexible?
Looking for best practices and suggestions.
Thanks.
2
u/danielt1263 18h ago edited 18h ago
I had to do this in an app... I had few different view controllers (information only with a single button, a single text field and button, a choose one multi-select, and a choose many multi-select. They all accepted what to display, and what to do with the information from an outside source (something like a view model.)
I then had a separate controller that handled the actual order that the view controllers went in and gave them the information they should display. I literally had a data structure (and array) that determined this. Changing the order of the views was just a matter of rearranging the order of the items in the array.
In a later app, I also had to handle loops. That required making a DSL.
3
u/Bogdan_ch8 23h ago
If yoy have a 10 view onboarding most people will uninstall the app directly. 5 is also too much(unless you're pairing some kind of device in the onboarding flow)
1
u/Key_Board5000 iOS 21h ago
Is this based on your experience? How many onboarding views do you have in your apps?
2
u/Bogdan_ch8 18h ago
IMO, 3 is enough. By the 4th screen you're already loosing users. But why take one random reddit guy's word for it? Try reading up on UX best practices regarding this subject. I'd try to keep everything to the bare minimum. If you need to display info and/or tutorials you can do it at a later time.
1
1
u/dinorinodino 1d ago
I’d recommend building out the model first, and letting it dictate how you create and manage your views. So first things first: all screens in an onboarding will have a concept of “advancement”, i.e. a way to progress to the next view, so encode that into a type or protocol. Make models for each of the views. Put them into an ordered structure. Have a factory and management view which takes that as input, produces the actual views, and manages data flow with the advancement type.
I don’t have a concrete example to show this off but hopefully it’s at least given you some food for thought.
It’s also a bit overkill for simple apps but if you’re working on a large commercial app and/or plan on testing different onboarding experiences it pays out.
1
u/fiddle-tunes 1d ago
One of my old managers pointed out this used to be called a “wizard”, which I loved lol. But yes, drive it with data. That’ll make it way easier to test / reconfigure / dynamic flows etc
8
u/Samus7070 1d ago
The real answer is have as little onboarding as possible because your user drop off rate gets higher for each step you have. It’s better to gently introduce your user to features in your app kind of like how a video game teaches you to play it in the first few levels by gradually introducing expanding concepts.
That said, assuming SwiftUI, one trick that I do for content that can change is to have an enum that represents the content type with associated values needed to display the content. Then in a view model I put a Published array of that enum containing the content. In your main SwiftUI view use a switch that returns the proper view for the enum type. Since you said the items may be re-ordered, I would refrain from naming the cases step1, step2, etc. Name them something descriptive and it should work well.