wedusa
(Marina Eremina)
1
I have code like this
let index = tableView.selectedRowIndexes.map { Int($0) }
arrDomains.remove(at: index)
But get error
Cannot convert value of type '[Int]' to expected argument type 'Int'
How convert [Int] to int?
In this case, no conversion is needed.
Solution:
let indexes = tableView.selectedRowIndexes.map { Int($0) }
indexes.reversed().forEach { arrDomains.remove(at: $0) }
This question is marked as off-topic because it contains API not related to the open source project itself.
I cannot look up the API atm. but judging from what it does, your logic has some issues. The propery returns an [Int] which means that 0 to n cells are selected. You should iterate over the array and decide what to do with each index.
Other than that stdlib has a reduce function to merge each value of the array to a result type.
[1, 2].reduce(3) { $0 + $1 } // returns 6
wedusa
(Marina Eremina)
3
Solution:
let indexes = tableView.selectedRowIndexes.map { Int($0) }
indexes.reversed().forEach { arrDomains.remove(at: $0) }
sveinhal
(Svein Halvor Halvorsen)
4
tableView.selectedRowIndexes
.map { Int($0) }
.reversed()
.forEach { arrDomains.remove(at: $0) }