Skip to content

Instantly share code, notes, and snippets.

@ttilley
Created September 23, 2015 08:23
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 ttilley/a9bef59dd0cb93fb52a9 to your computer and use it in GitHub Desktop.
Save ttilley/a9bef59dd0cb93fb52a9 to your computer and use it in GitHub Desktop.
func tupleToArray<T, U>(var tuple: T, _ resultType: U.Type) -> [U] {
let count = sizeof(T) / sizeof(U)
return withUnsafePointer(&tuple) { ptr -> [U] in
let eltPtr = UnsafePointer<U>(ptr)
return Array(0..<count).map({ eltPtr[$0] })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment