Conditional views with empty else clause crashes #41

Closed
opened 2025-10-14 15:43:56 -06:00 by navan · 0 comments
Owner

Originally created by @hassila on 12/16/2022

Constructs like this crashes with a nil dereference:

        if let statistics {
                VStack {
                    HStack {
                        VStack {
                            Text("Table statistics")
                            TableStatisticsView(statistics: statistics)
                                .border()
                        }
                        Spacer()
                    }
                }
            } 

adding an else clause returning a different view get's it working:

else {
                Spacer()
            }

Seems conditional views can't handle the case of 'empty' - maybe 'EmptyView' could be exposed if an else clause is required?
(I don't want to use a Spacer) - need scope change:

'EmptyView' initializer is inaccessible due to 'internal' protection level

Should this work, or must a view always be returned in else? If so, could we consider exposing EmptyView ?

*Originally created by @hassila on 12/16/2022* Constructs like this crashes with a nil dereference: ``` if let statistics { VStack { HStack { VStack { Text("Table statistics") TableStatisticsView(statistics: statistics) .border() } Spacer() } } } ``` adding an else clause returning a different view get's it working: ``` else { Spacer() } ``` Seems conditional views can't handle the case of 'empty' - maybe 'EmptyView' could be exposed if an else clause is required? (I don't want to use a Spacer) - need scope change: `'EmptyView' initializer is inaccessible due to 'internal' protection level` Should this work, or must a view always be returned in else? If so, could we consider exposing EmptyView ?
navan closed this issue 2025-10-14 15:43:56 -06:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/SwiftTUI#41
No description provided.