Core data swift 3重新排序具有核心数据的collectionView单元格

Core data swift 3重新排序具有核心数据的collectionView单元格,core-data,swift3,uicollectionviewcell,Core Data,Swift3,Uicollectionviewcell,请帮助在集合视图中重新排序,这是我的代码,不起作用。我不明白为什么 var dataEntity = [Chart]() // my Core data func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { let context = (UIApplication.shar

请帮助在集合视图中重新排序,这是我的代码,不起作用。我不明白为什么

 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)")
        }



}