Change force unwraps so that we just fail on the move instead of crashing
This commit is contained in:
parent
c47480614c
commit
0ac3ba0bbb
@ -370,22 +370,28 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
return IndexPath(row: 0, section: destIndexPath.section)
|
return IndexPath(row: 0, section: destIndexPath.section)
|
||||||
} else {
|
} else {
|
||||||
let identifier = makeIdentifier(sortedNodes[index])
|
let identifier = makeIdentifier(sortedNodes[index])
|
||||||
let candidateIndexPath = dataSource.indexPath(for: identifier)!
|
if let candidateIndexPath = dataSource.indexPath(for: identifier) {
|
||||||
let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0
|
let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0
|
||||||
return IndexPath(row: candidateIndexPath.row - movementAdjustment, section: candidateIndexPath.section)
|
return IndexPath(row: candidateIndexPath.row - movementAdjustment, section: candidateIndexPath.section)
|
||||||
|
} else {
|
||||||
|
return sourceIndexPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if index >= sortedNodes.count {
|
if index >= sortedNodes.count {
|
||||||
let identifier = makeIdentifier(sortedNodes[sortedNodes.count - 1])
|
let identifier = makeIdentifier(sortedNodes[sortedNodes.count - 1])
|
||||||
let lastSortedIndexPath = dataSource.indexPath(for: identifier)!
|
if let lastSortedIndexPath = dataSource.indexPath(for: identifier) {
|
||||||
let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0
|
let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0
|
||||||
return IndexPath(row: lastSortedIndexPath.row + movementAdjustment, section: lastSortedIndexPath.section)
|
return IndexPath(row: lastSortedIndexPath.row + movementAdjustment, section: lastSortedIndexPath.section)
|
||||||
|
} else {
|
||||||
|
return sourceIndexPath
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0
|
let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0
|
||||||
let identifer = makeIdentifier(sortedNodes[index - movementAdjustment])
|
let identifer = makeIdentifier(sortedNodes[index - movementAdjustment])
|
||||||
return dataSource.indexPath(for: identifer)!
|
return dataSource.indexPath(for: identifer) ?? sourceIndexPath
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user