Skip to content

Instantly share code, notes, and snippets.

@mitulmanish
Created July 6, 2016 07:03
Show Gist options
  • Save mitulmanish/09c605bcbf673b50a1bb8dec8d68e658 to your computer and use it in GitHub Desktop.
Save mitulmanish/09c605bcbf673b50a1bb8dec8d68e658 to your computer and use it in GitHub Desktop.
Iterating over 2D array in Swift(with indices)
let twoDimArr: [[Int]] = [[0, 0, 1], [1, 0, 1]]
for (i,row) in twoDimArr.enumerate() {
for (j, cell) in row.enumerate() {
print("m[\(i),\(j)] = \(cell)")
print("**************")
}
}
@mmmahajan
Copy link

mmmahajan commented May 3, 2018

For Swift 3
for (i,row) in twoDimArr.enumerated() {
for (j, cell) in row.enumerated() {
print("m[(i),(j)] = (cell)")
print("**************")
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment