Skip to content

Instantly share code, notes, and snippets.

@benlmyers
Created June 22, 2021 23:42
Show Gist options
  • Save benlmyers/68fd4de9090cb18dfd8d70775c3821b4 to your computer and use it in GitHub Desktop.
Save benlmyers/68fd4de9090cb18dfd8d70775c3821b4 to your computer and use it in GitHub Desktop.
A quick way to add together views using the + operator.
import SwiftUI
extension View {
static func + <T> (lhs: Self, rhs: T) -> some View where T: View {
HStack {
lhs
rhs
}
}
}
/// Example of using this operator:
/// ```
/// Image(systemName: "hand.wave") + Text("Hello, quicker SwiftUI!")
/// ```
/// Views added together are quickly embedded in an HStack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment