Created
September 19, 2018 10:10
-
-
Save AlonsoFloo/c2c1bfbe6d2dbd15754c60df1014b021 to your computer and use it in GitHub Desktop.
Array util for SWIFT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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