Hi below code was working fine in swift1.2 but when I upgraded to swift 2.0:
func deselectAllRows() {
if let selectedRows = tableView.indexPathsForSelectedRows as! [NSIndexPath] {
for indexPath in selectedRows {
tableView.deselectRowAtIndexPath(indexPath, animated: false)
}
}
}
It shows the following error :
Downcast from '[NSIndexPath]?' to '[indexpath]' only unwraps optional
Any clue on how to resolve this issue?
You don't have to force a typecast anymore, indexPathsForSelectedRows returns the right type:
func deselectAllRows() {
if let selectedRows = tableView.indexPathsForSelectedRows {
for indexPath in selectedRows {
tableView.deselectRowAtIndexPath(indexPath, animated: false)
}
}
}
The tableView.indexPathsForSelectedRows returns [NSIndexPath]?, so you don't need to type cast it. You can just write it like:
func deselectAllRows()
{
if let selectedRows = tableView.indexPathsForSelectedRows
{
for indexPath in selectedRows
{
tableView.deselectRowAtIndexPath(indexPath, animated: false)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With