SwiftUI ViewBuilder is resultBuilder, and from Swift 5.3 you can declare if let, if case, multiple if statements, switch, ... pretty much like a normal block function.
ViewBuilder is recommended to leverage SwiftUI type system to ensure performance. Here are a few examples 👇
Local variables.
Pretty much like a normal function, you can declare local variables and return View at last.
Mix if and switch statements
This is handy when you want to show modal or overlay of different Views
If statement only.
No more if else with EmptyView, you can just return View for the happy path.
Empty return.
For function marked with ViewBuilder, you don't need to return anything
Return nil.
Optional conforms to SwiftUI View as long as its Wrapped conforms to View. So we can return nil from ViewBuilder
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Have you recently discovered some nifty UIKit APIs that you wish you had known earlier?
Apple introduces new changes every WWDC but it may take a while until they can be adopted in production, hence developers forgot.
Here are 9 useful APIs from iOS 7 - 15 many fail to notice
keyboardDismissMode, iOS 7
Have you tried making the keyboard dismissal follow along drag gesture? It's not an easy feast but I still see manual implementation in some codebases.
They didn't know that in iOS 7, you can specify keyboardDismissMode to be .interactive.