Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save onmyway133/86dece46817529b4ee8c to your computer and use it in GitHub Desktop.
Save onmyway133/86dece46817529b4ee8c 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