-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ede3eba
commit 21771ea
Showing
3 changed files
with
138 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Copyright (c) Nathan Tannar | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension ForEach { | ||
@_disfavoredOverload | ||
@inlinable | ||
public init<_Data: RandomAccessCollection>( | ||
_ data: _Data, | ||
@ViewBuilder content: @escaping (_Data.Index, _Data.Element) -> Content | ||
) where Data == Array<(_Data.Index, _Data.Element)>, ID == _Data.Index, Content: View { | ||
let elements = Array(zip(data.indices, data)) | ||
self.init(elements, id: \.0) { index, element in | ||
content(index, element) | ||
} | ||
} | ||
|
||
@inlinable | ||
public init< | ||
_Data: RandomAccessCollection | ||
>( | ||
_ data: _Data, | ||
id: KeyPath<_Data.Element, ID>, | ||
@ViewBuilder content: @escaping (_Data.Index, _Data.Element) -> Content | ||
) where Data == Array<(_Data.Index, _Data.Element)>, Content: View { | ||
let elements = Array(zip(data.indices, data)) | ||
let elementPath: KeyPath<(_Data.Index, _Data.Element), _Data.Element> = \.1 | ||
self.init(elements, id: elementPath.appending(path: id)) { index, element in | ||
content(index, element) | ||
} | ||
} | ||
|
||
@inlinable | ||
public init< | ||
_Data: RandomAccessCollection | ||
>( | ||
_ data: _Data, | ||
@ViewBuilder content: @escaping (_Data.Index, _Data.Element) -> Content | ||
) where Data == Array<(_Data.Index, _Data.Element)>, _Data.Element: Identifiable, ID == _Data.Element.ID, Content: View { | ||
let elements = Array(zip(data.indices, data)) | ||
self.init(elements, id: \.1.id) { index, element in | ||
content(index, element) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - ForEach Previews | ||
|
||
struct ForEach_Previews: PreviewProvider { | ||
struct Model: Identifiable { | ||
var id = UUID().uuidString | ||
} | ||
static var previews: some View { | ||
VStack { | ||
ForEach([10, 20, 30]) { index, number in | ||
Text("\(index): \(number)") | ||
} | ||
|
||
ForEach([10, 20, 30], id: \.self) { index, number in | ||
Text("\(index): \(number)") | ||
} | ||
|
||
ForEach([Model()]) { index, model in | ||
Text("\(index): \(model.id)") | ||
} | ||
} | ||
} | ||
} |
This file contains 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
26 changes: 0 additions & 26 deletions
26
Sources/Turbocharger/Sources/View/ProposedSizeObserver.swift
This file was deleted.
Oops, something went wrong.
21771ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathantannar4 is the ProposedSizeObserver file removed by mistake? It's still used here so now build is broken:
Turbocharger/Sources/Turbocharger/Sources/View/ProposedSizeReader.swift
Line 19 in b71236b