Skip to content
Ever wonder why Swift crashes if you access a collection the wrong way? Me too here's some extensions
Swift
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
.swiftpm/xcode/package.xcworkspace
Sources/SafeCollectionAccess
Tests
.gitignore
Package.swift
README.md

README.md

Swift Safe Collection Access

Ever wonder why Swift crashes if you access a collection the wrong way? Especially an array? Me too here's some extensions.

Example

import SafeCollectionAccess



let first5Fibonacci = [1, 1, 2, 3, 5]

print(first5Fibonacci[orNil: 0]) // Optional(1)
print(first5Fibonacci[orNil: 0] == first5Fibonacci[safe: 1]) // true
print(first5Fibonacci[safe: 5]) // nil
You can’t perform that action at this time.