Skip to content

Instantly share code, notes, and snippets.

@JJC1138
Created November 14, 2016 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJC1138/501ef8186cab49a8f780c2345cff94e7 to your computer and use it in GitHub Desktop.
Save JJC1138/501ef8186cab49a8f780c2345cff94e7 to your computer and use it in GitHub Desktop.
extension Collection {
subscript(safe index: Index) -> Iterator.Element? {
var testIndex = startIndex
while testIndex != endIndex {
if testIndex == index {
return self[index]
}
testIndex = self.index(after: testIndex)
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment