Convert selectedindexpath.row to integer?

I have the following loop in my code:


for i in 0..<array.count where newRow != i {

array{i].active = false

}


I would like to assign the selectedIndexPath.row to the variable newRow. Is that possible or is there a better way to make the loop ignore the current row I am on?


Thanks in advance for any help.

Accepted Reply

You are not showing enough info, so I may be missing something, but why won't you do it simply:

                for i in 0..<todos.count where selectedIndexPath.row != i {
                    todos[i].activated = false
                }


Or, when I want TO SET ACTIVATED TO TRUE IN THIS ROW AND FALSE IN ALL OTHER ROWS, I would write:

                for i in 0..<todos.count {
                    todos[i].activated = (selectedIndexPath.row == i)
                }

Replies

Please show more context. What is `selectedIndexPath`? Where and how you declare it? Especially, what is the type of it?

THIS IS THE CODE:


if let todo = sourceViewController.todo {

if let selectedIndexPath =

tableView.indexPathForSelectedRow {

todos[selectedIndexPath.row] = todo

tableView.reloadRows(at: [selectedIndexPath],

with: .none)


I WOULD LIKE TO ADD CODE HERE TO SET ACTIVATED TO TRUE IN THIS ROW AND FALSE IN ALL OTHER ROWS:

for i in 0..<todos.count where newRow != i {

todos[i].activated = false

}

You are not showing enough info, so I may be missing something, but why won't you do it simply:

                for i in 0..<todos.count where selectedIndexPath.row != i {
                    todos[i].activated = false
                }


Or, when I want TO SET ACTIVATED TO TRUE IN THIS ROW AND FALSE IN ALL OTHER ROWS, I would write:

                for i in 0..<todos.count {
                    todos[i].activated = (selectedIndexPath.row == i)
                }