forked from aparoksha/adwaita-swift
Merge branch 'main' of https://github.com/AparokshaUI/adwaita-swift
This commit is contained in:
commit
50b22115b0
16
.spi.yml
16
.spi.yml
@ -1,3 +1,17 @@
|
|||||||
version: 1
|
version: 1
|
||||||
external_links:
|
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
|
||||||
|
|||||||
@ -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.
|
/// Get a child at a certain index of the array as a binding.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - index: The child's index.
|
/// - index: The child's index.
|
||||||
/// - defaultValue: The value used if the index is out of range does not exist.
|
/// - defaultValue: The value used if the index is out of range does not exist.
|
||||||
/// - Returns: The child as a binding.
|
/// - 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 {
|
.init {
|
||||||
wrappedValue[safe: index] ?? defaultValue
|
if let index, wrappedValue.indices.contains(index) {
|
||||||
|
return wrappedValue[index] ?? defaultValue
|
||||||
|
}
|
||||||
|
return defaultValue
|
||||||
} set: { newValue in
|
} set: { newValue in
|
||||||
wrappedValue[safe: index] = newValue
|
if let index, wrappedValue.indices.contains(index) {
|
||||||
|
wrappedValue[index] = newValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user