diff --git a/Contributors.md b/Contributors.md index 882dae1..6abe660 100644 --- a/Contributors.md +++ b/Contributors.md @@ -2,3 +2,4 @@ - [david-swift](https://github.com/david-swift) - [Greg Cotten](https://github.com/gregcotten) +- [Zev Eisenberg](https://github.com/ZevEisenberg) diff --git a/Sources/Adwaita/Model/Extensions/Array.swift b/Sources/Adwaita/Model/Extensions/Array.swift index a5136b3..e8566d0 100644 --- a/Sources/Adwaita/Model/Extensions/Array.swift +++ b/Sources/Adwaita/Model/Extensions/Array.swift @@ -91,23 +91,16 @@ extension Array { /// ``` public subscript(safe index: Int?) -> Element? { get { - if let index, checkIndex(index) { + if let index, indices.contains(index) { return self[index] } return nil } set { - if let index, let value = newValue, checkIndex(index) { + if let index, let value = newValue, indices.contains(index) { self[index] = value } } } - /// Check if a given index is valid for the array. - /// - Parameter index: The index to test. - /// - Returns: Return whether the index is valid or not. - private func checkIndex(_ index: Int) -> Bool { - index < count && index >= 0 - } - }