Closed wousser closed 5 years ago
In the new Todo example, I see
if state.todos.isEmpty {
Section(id: ID.task, header: TodoEmpty())
}
else {
Section(
id: ID.task,
header: Header("TASKS (\(state.todos.count))"),
cells: { }
)
Is the correct way from now on to specify a Section for each header?
@wousser
Generic parameters require the same type for both components at compile time.
This follows the specification of SwiftUI.
Until rc2, ViewNode has played the role of type-erasure, but that isn't the case now.
You can use AnyComponent
instead.
Section(
id: "contactToday",
header: state.today.isEmpty
? AnyComponent(TodayEmpty())
: AnyComponent(TodayHeader()),
cells: { ... }
)
Checklist
Expected Behavior
In RC2 it was possible two show a different heading based on a flag
Current Behavior
In RC4 this behavior is not possible anymore. Resulting in this error: Result values in '? :' expression have mismatching types 'TodayEmpty' and 'TodayHeader'
Detailed Description (Include Screenshots)
Both are Component: struct TodayEmpty : Component struct TodayHeader : Component
Environment
Is this possible in RC4 and onwards?