Last active
July 8, 2019 16:58
-
-
Save pteasima/236a5abb66bdf3f8510594c3faff6391 to your computer and use it in GitHub Desktop.
Useless Static ForEach (use Group instead)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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