Skip to content

Instantly share code, notes, and snippets.

@AlonsoFloo
Created September 19, 2018 10:10
Show Gist options
  • Save AlonsoFloo/c2c1bfbe6d2dbd15754c60df1014b021 to your computer and use it in GitHub Desktop.
Save AlonsoFloo/c2c1bfbe6d2dbd15754c60df1014b021 to your computer and use it in GitHub Desktop.
Array util for SWIFT
import UIKit
extension Collection where Indices.Iterator.Element == Index {
/// Returns the element at the specified index iff it is within bounds, otherwise nil.
subscript (safe index: Index) -> Generator.Element? {
return indices.contains(index) ? self[index] : nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment