Skip to content

Instantly share code, notes, and snippets.

@almostintuitive
Created September 19, 2015 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save almostintuitive/89e99c9c31f9830260db to your computer and use it in GitHub Desktop.
Save almostintuitive/89e99c9c31f9830260db to your computer and use it in GitHub Desktop.
Use NSHashTable with for .. in .. style enumeration with Swift2 (safely)
extension NSHashTable: SequenceType {
public func generate() -> AnyGenerator<AnyObject> {
var array = self.allObjects
var nextIndex = array.count-1
return anyGenerator {
if (nextIndex < 0) {
return nil
}
return array[nextIndex--]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment