Skip to content

Instantly share code, notes, and snippets.

@ahcode0919
Last active April 17, 2017 22:54
Show Gist options
  • Save ahcode0919/76282e68c951fab95c902b850e6606e6 to your computer and use it in GitHub Desktop.
Save ahcode0919/76282e68c951fab95c902b850e6606e6 to your computer and use it in GitHub Desktop.
Swift Zip function usage
//Zip function (Sequence)
// https://github.com/apple/swift/blob/master/stdlib/public/core/Zip.swift
// https://developer.apple.com/reference/swift/1541125-zip
// http://swiftdoc.org/v3.0/func/zip/
let array1 = ["one", "two", "three", "four", "five"]
let array2 = 1...5
let zipSequence = zip(array1, array2)
type(of: zipSequence) //Zip2Sequence<Array<String>, CountableClosedRange<Int>>.Type
zipSequence.forEach { (key, value) in
print("key: \(key), value: \(value)")
}
//key: one, value: 1
//key: two, value: 2
//key: three, value: 3
//key: four, value: 4
//key: five, value: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment