https://github.com/devxoul/safecollection
Safe Collection for Swift
https://github.com/devxoul/safecollection
array optional subscript swift
Last synced: 3 months ago
JSON representation
Safe Collection for Swift
- Host: GitHub
- URL: https://github.com/devxoul/safecollection
- Owner: devxoul
- License: mit
- Created: 2016-02-18T09:02:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-03T13:03:50.000Z (about 6 years ago)
- Last Synced: 2025-03-18T08:53:27.745Z (3 months ago)
- Topics: array, optional, subscript, swift
- Language: Swift
- Homepage:
- Size: 26.4 KB
- Stars: 43
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SafeCollection

[](https://travis-ci.org/devxoul/SafeCollection)
[](https://cocoapods.org/pods/SafeCollection)
[](https://github.com/Carthage/Carthage)SafeCollection provides a safer way to deal with subscripts. Inspired by Swift's [LazyCollection](https://developer.apple.com/documentation/swift/lazycollection).
## At a Glance
```swift
let arr = ["A", "B", "C"]arr[0] // "A"
arr[100] // fatal error: Array index out of range 😟arr.safe[0] // Optional("A")
arr.safe[100] // nil 😄
```## Installation
- **For iOS 8+ projects** with [CocoaPods](https://cocoapods.org):
```ruby
pod 'SafeCollection'
```- **For iOS 8+ projects** with [Carthage](https://github.com/Carthage/Carthage):
```
github "devxoul/SafeCollection"
```- **Using [Swift Package Manager](https://swift.org/package-manager)**:
```swift
import PackageDescriptionlet package = Package(
name: "MyAwesomeApp",
dependencies: [
.package(url: "https://github.com/devxoul/SafeCollection", .upToNextMajor(from: "3.0.0")),
]
)
```## License
SafeCollection is under MIT license. See the [LICENSE](LICENSE) file for more info.