Skip to content

Instantly share code, notes, and snippets.

@JanGorman
Created January 18, 2020 10:11
Show Gist options
  • Save JanGorman/23fecdb8e54e01db416c7f168ecd0ff8 to your computer and use it in GitHub Desktop.
Save JanGorman/23fecdb8e54e01db416c7f168ecd0ff8 to your computer and use it in GitHub Desktop.
Alternative to using .enumerated() and then having to add + 1 to the index for lists
struct Person {
let name: String
init(_ name: String) {
self.name = name
}
}
let people: [Person] = [.init("De Konig"), .init("Pollock"), .init("Rothko"), .init("Kandinsky")]
for (number, person) in zip(1..., people) {
print("\(number). \(person.name)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment