Skip to content

Commit 9320d3a

Browse files
committed
Add support for ForEach
1 parent 1530ea2 commit 9320d3a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Foundation
2+
3+
public struct ForEach<Data, ID, Content> where Data: RandomAccessCollection, ID: Hashable {
4+
public var data: Data
5+
public var content: (Data.Element) -> Content
6+
}
7+
8+
extension ForEach: View where Content: View {
9+
public var body: Never {
10+
fatalError()
11+
}
12+
13+
public typealias Body = Never
14+
public static func _makeView(view: _GraphValue<ForEach<Data, ID, Content>>, inputs: _ViewInputs) -> _ViewOutputs {
15+
fatalError()
16+
}
17+
public static func _makeViewList(view: _GraphValue<ForEach<Data, ID, Content>>, inputs: _ViewListInputs) -> _ViewListOutputs {
18+
fatalError()
19+
}
20+
}
21+
22+
extension ForEach where ID == Data.Element.ID, Content: View, Data.Element: Identifiable {
23+
public init(_ data: Data, @ViewBuilder content: @escaping (Data.Element) -> Content) {
24+
self.data = data
25+
self.content = content
26+
}
27+
}
28+
29+
extension ForEach where Content: View {
30+
public init(_ data: Data, id: KeyPath<Data.Element, ID>, content: @escaping (Data.Element) -> Content) {
31+
self.data = data
32+
self.content = content
33+
}
34+
}
35+
36+
extension ForEach where Data == Range<Int>, ID == Int, Content: View {
37+
public init(_ data: Range<Int>, @ViewBuilder content: @escaping (Int) -> Content) {
38+
self.data = data
39+
self.content = content
40+
}
41+
}

0 commit comments

Comments
 (0)