Skip to content

Instantly share code, notes, and snippets.

@justAnotherDev
Created January 5, 2016 20:30
Show Gist options
  • Save justAnotherDev/924d283c4aea0da41ad0 to your computer and use it in GitHub Desktop.
Save justAnotherDev/924d283c4aea0da41ad0 to your computer and use it in GitHub Desktop.
Iterate a tuple in Swift
func generatorForTuple(tuple: Any) -> AnyGenerator<Any> {
return anyGenerator(Mirror(reflecting: tuple).children.lazy.map { $0.value }.generate())
}
let someTuple = ("1", 2, ["3"])
for value in generatorForTuple(someTuple) {
print(value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment