- SwiftUI is not able to render more than 10 child elements per parent
- Multiple
Group
elements mitigate this limitation- No visual effect, used to display more than 10 child elements
- Multiple
Section
elements enable the same- Visually separated, see iOS Settings view for an example
- Multiple
- Safe space:
- Space on the display where it is safe to display things without running into possible problems (e.g. occlusion)
- On modern iPhones the safe space goes from below the notch down to the home indicator
- For scrollable elements like a
Form
this might cause problems, as it will be hidden behind the notch (and the clock) on scroll - Adding a navigation bar by wrapping a view inside a
NavigationView
avoids this problem as it properly scrolls behind the top navigation bar- If we want to set a title on the navigation bar we can do this by:
- Adding the
.navigationTitle(title: string)
modifier to the wrapped element will set a large title (like on the main screen of iOS settings) - Adding the additional modifier
.navigationBarTitleDisplayMode(.inline)
will display a small title, like on the subsequent settings pages on iOS
- Adding the
- If we want to set a title on the navigation bar we can do this by:
- State
- SwiftUI relies on immutable structs instead of classes for views
- Views are re-rendered multiple times, having immutable data avoids side-effects
- Thus, it's not possible to store state in plain struct fields
- The special SwiftUI property wrapper
@State
solves this issue - Stores data in a separate, modifiable place.
- So every
@State
property is effectively a reference?
- The special SwiftUI property wrapper
- SwiftUI relies on immutable structs instead of classes for views