Skip to content

Commit 75ad98c

Browse files
authored
Update IfCaseLet.swift (pointfreeco#22)
* Update IfCaseLet.swift * Conform ElseContent to View
1 parent f615959 commit 75ad98c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/SwiftUINavigation/IfCaseLet.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import SwiftUI
3636
///
3737
/// To exhaustively handle every case of a binding to an enum, see ``Switch``. Or, to unwrap a
3838
/// binding to an optional, see ``IfLet``.
39-
public struct IfCaseLet<Enum, Case, IfContent, ElseContent>: View where IfContent: View {
39+
public struct IfCaseLet<Enum, Case, IfContent, ElseContent>: View where IfContent: View, ElseContent: View {
4040
public let `enum`: Binding<Enum>
4141
public let casePath: CasePath<Enum, Case>
4242
public let ifContent: (Binding<Case>) -> IfContent
@@ -69,7 +69,11 @@ public struct IfCaseLet<Enum, Case, IfContent, ElseContent>: View where IfConten
6969
}
7070

7171
public var body: some View {
72-
Binding(unwrapping: self.enum, case: self.casePath).map(self.ifContent)
72+
if let caseBinding = Binding(unwrapping: self.enum, case: self.casePath) {
73+
ifContent(caseBinding)
74+
} else {
75+
elseContent()
76+
}
7377
}
7478
}
7579

0 commit comments

Comments
 (0)