Last active
May 22, 2017 13:16
-
-
Save bennokress/ece30a2dabc8bf118b2b01b6454e9f35 to your computer and use it in GitHub Desktop.
Extensions for Swift's Collection Type
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 { | |
// Usage: array[optional: 2] --> returns element at position 2 if possible, else returns nil | |
subscript(optional i: Index) -> Iterator.Element? { | |
return (self.startIndex ..< self.endIndex).contains(i) ? self[i] : nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment