Last active
May 29, 2019 00:26
-
-
Save tularovbeslan/56c2344e1c4a624488d7dab0e88d33cb to your computer and use it in GitHub Desktop.
Handling Index Out of Range Exception the Swift Way
This file contains hidden or 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
extension Collection { | |
subscript(safe index: Index) -> 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