Mismatched header types
wousser opened this issue · 2 comments
wousser commented
Checklist
- Reviewed the README and documents.
- Searched existing issues for ensure not duplicated.
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)
Section(
id: "contactToday",
header: state.today.isEmpty
? TodayEmpty() : TodayHeader(),
cells: { }
)
Both are Component:
struct TodayEmpty : Component
struct TodayHeader : Component
Environment
- Carbon version:
RC4 - Swift version:
Is this possible in RC4 and onwards?
wousser commented
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?
ra1028 commented
@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: { ... }
)