Skip to content

Instantly share code, notes, and snippets.

@shankartshinde
Created May 8, 2018 06:39
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 shankartshinde/5e6b068b5a655aafc8d8f836fdb06cfc to your computer and use it in GitHub Desktop.
Save shankartshinde/5e6b068b5a655aafc8d8f836fdb06cfc to your computer and use it in GitHub Desktop.
Iterate two dimensional array in swift
import UIKit
let twoDiamentionalArray = [
["Shankar","Archana","Amol","Shivaji","Ketan"],
["Mumbai","Pune","Dehli","Hyderabad"],
["Elephant","Cat","Dog","Cow","Tiger","Lion"]
]
let sectionNames = ["Best Friends","Beautiful Cities","Faviorate Animal"]
var showIndexPaths = true
func doAnimationForSection() {
var indexPathsToReload = [IndexPath]()
for section in stride(from: 0, to: twoDiamentionalArray.count, by:1) {
//print("\(index) with value \(value)")
for row in stride(from: 0, to:twoDiamentionalArray[section].count , by:1) {
//print("for section \(section) with row \(row)")
let newIndexPath = IndexPath(row: row, section: section)
indexPathsToReload.append(newIndexPath)
}
}
// let animationStyle = showIndexPaths ? UITableViewRowAnimation.left :UITableViewRowAnimation.right
// tableView.reloadRows(at: indexPathsToReload, with: animationStyle)
showIndexPaths = !showIndexPaths
for sec in twoDiamentionalArray.indices {
for row in twoDiamentionalArray[sec].indices {
print("for section \(sec) with row \(row)")
}
}
}
doAnimationForSection()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment