priority
The layout priority of the subview.
Declaration
var priority: Double { get }Discussion
If you define a custom layout type using the Layout protocol, you can read this value from subviews and use the value when deciding how to assign space to subviews. For example, you can read all of the subview priorities into an array before placing the subviews in a custom layout type called BasicVStack:
extension BasicVStack {
func placeSubviews(
in bounds: CGRect,
proposal: ProposedViewSize,
subviews: Subviews,
cache: inout ()
) {
let priorities = subviews.map { subview in
subview.priority
}
// Place views, based on priorities.
}
}Set the layout priority for a view that appears in your layout by applying the layoutPriority(_:) view modifier. For example, you can assign two different priorities to views that you arrange with BasicVStack:
BasicVStack {
Text("High priority")
.layoutPriority(10)
Text("Low priority")
.layoutPriority(1)
}