Skip to content

Commit def5c35

Browse files
committed
🔮 Add operator shorthand for type erasing
1 parent 107b8e5 commit def5c35

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

‎SwiftUI2048/SwiftUIExtensions.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ extension View {
1515
}
1616

1717
}
18+
19+
postfix operator >*
20+
postfix func >*<V>(lhs: V) -> AnyView where V: View {
21+
return lhs.eraseToAnyView()
22+
}

‎SwiftUI2048/Views/GameView.swift‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,10 @@ struct GameView : View {
115115
}
116116

117117
var body: AnyView {
118-
if gestureEnabled {
119-
return content
120-
.gesture(gesture, including: .all)
121-
.eraseToAnyView()
122-
}
123-
return content.eraseToAnyView()
118+
return gestureEnabled ? (
119+
content
120+
.gesture(gesture, including: .all)>*
121+
) : content>*
124122
}
125123

126124
}

0 commit comments

Comments
 (0)