Last active
April 17, 2017 22:54
-
-
Save ahcode0919/76282e68c951fab95c902b850e6606e6 to your computer and use it in GitHub Desktop.
Swift Zip function usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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