Today I first learned more about container views in SwiftUI: Stacks, like
ZStack, how SwiftUI's layout system works, Lists, Forms, Scroll Views, Navigation, etc. I remember doing all these things in UIKit being much harder and needing a lot more code.
Next, I learned more about binding data to views. Some random notes:
ObservableObject protocol with
@Published property wrapper on properties you want to watch for changes
@ObservedObject property wrapper
@Binding property wrapper
.environmentObject(someReferenceType) used with
@EnvironmentObject property wrapper to inject dependencies
Lastly, I got an intro to accessibility with SwiftUI. In the past, I haven't done a very good job of making things I've made accessible. It's always been an afterthought because I'm privileged not to need assistance. SwiftUI and iOS makes it easy so I should be adding and testing accessibility from the start as I get into making my own apps. I added a VoiceOver toggle to the lock button if I triple press it.
Some notes on VoiceOver accessibility:
- Passing a decorative property to
Image removes the label from being read by VoiceOver
- You can hide elements from VoiceOver completely with
.accessibility(hidden: true) modifier
- You can provide a more understandable value with
.accessibility(value: "Some value")
- Call out specific headers for VoiceOver to recognize
There are many other accessibility features besides VoiceOver that I still need to learn more about. In the video I watched, it said Apple has three questions to keep in mind when developing for accessibility:
1. Do displayed strings provide enough information?
2. Would a custom action simplify the interaction?
3. Can you speed up navigation?
After using my phone with VoiceOver for a bit, number three resonated with me the most. It takes a while to navigate around with VoiceOver (Iam very experienced with it). I can see how if an app doesn't provide accessibility support or creates custom elements instead of using Apple's accessible versions, it can be very frustrating to get to where you want to go.