请帮忙在集合视图中重新排序,这里是我的代码,不起作用。我不明白为什么
var dataEntity = [Chart]() // my Core data
func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let source = dataEntity[sourceIndexPath.row]
let destination = dataEntity[destinationIndexPath.row]
dataEntity[sourceIndexPath.row] = destination
dataEntity[destinationIndexPath.row] = source
do {
try context.save()
print("save")
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
}