This commit is contained in:
david-swift 2024-04-04 15:30:45 +02:00
commit 50b22115b0
2 changed files with 24 additions and 5 deletions

View File

@ -1,3 +1,17 @@
version: 1
external_links:
documentation: "aparokshaui.github.io/adwaita-swift/"
documentation: "https://aparokshaui.github.io/adwaita-swift/"
builder:
configs:
- platform: linux
swift_version: '5.10'
image: registry.gitlab.com/finestructure/spi-images:adwaita-5.10-latest
- platform: linux
swift_version: '5.9'
image: registry.gitlab.com/finestructure/spi-images:adwaita-5.9-latest
- platform: linux
swift_version: '5.8'
image: registry.gitlab.com/finestructure/spi-images:adwaita-5.8-latest
- platform: linux
swift_version: '5.7'
image: registry.gitlab.com/finestructure/spi-images:adwaita-5.7-latest

View File

@ -105,18 +105,23 @@ extension Array {
}
extension Binding where Value == [Any] {
extension Binding where Value: MutableCollection {
/// Get a child at a certain index of the array as a binding.
/// - Parameters:
/// - index: The child's index.
/// - defaultValue: The value used if the index is out of range does not exist.
/// - Returns: The child as a binding.
public subscript(safe index: Int?, default defaultValue: Value.Element) -> Binding<Value.Element> {
public subscript(safe index: Value.Index?, default defaultValue: Value.Element) -> Binding<Value.Element> {
.init {
wrappedValue[safe: index] ?? defaultValue
if let index, wrappedValue.indices.contains(index) {
return wrappedValue[index] ?? defaultValue
}
return defaultValue
} set: { newValue in
wrappedValue[safe: index] = newValue
if let index, wrappedValue.indices.contains(index) {
wrappedValue[index] = newValue
}
}
}