swift 3重新排序集合核心数据的单元格

时间:2016-12-12 15:16:06

标签: core-data swift3 uicollectionviewcell

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

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



}

0 个答案:

没有答案