Created
May 8, 2018 06:39
-
-
Save shankartshinde/5e6b068b5a655aafc8d8f836fdb06cfc to your computer and use it in GitHub Desktop.
Iterate two dimensional array in swift
This file contains hidden or 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
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