Skip to content

Instantly share code, notes, and snippets.

@pteasima
Last active July 8, 2019 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pteasima/236a5abb66bdf3f8510594c3faff6391 to your computer and use it in GitHub Desktop.
Save pteasima/236a5abb66bdf3f8510594c3faff6391 to your computer and use it in GitHub Desktop.
Useless Static ForEach (use Group instead)
import SwiftUI
extension ForEach where Data == Range<Int>{
init(_ v1: @autoclosure @escaping () -> Content) {
self.init(0..<1) { _ in
v1()
}
}
init<V1, V2>(
_ v1: @autoclosure @escaping () -> V1,
_ v2: @autoclosure @escaping () -> V2
) where Content == ConditionalContent<V1, V2> {
self.init(0..<2) { idx in
if idx == 0 {
v1()
} else {
v2()
}
}
}
}
#if DEBUG
struct Playground: PreviewProvider {
static var previews: some View {
ForEach(
Text("bar"),
Button(action: {}) { Text("foo") }
)
.previewLayout(.sizeThatFits)
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment