How to make Core Data order records like the order of an array?

Hi there!
I want to bring the records of CoreData in the same order like my array. How can I do that?

That’s my code:

override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)
    {
        
        var destinationData = folders
        let folder = folders[sourceIndexPath.row]
        
        
        if sourceIndexPath != destinationIndexPath
        {
            folders.removeAtIndex(sourceIndexPath.row)
            folders.insert(folder, atIndex: destinationIndexPath.row)
            swap(&destinationData[destinationIndexPath.row], &destinationData[sourceIndexPath.row])
            saveData()
        }
        
    }

Sorry for the simple english, I’m from Germany and I do my best. :smiley:

Thanks! :slight_smile:

Let me understand you.

Normally with Core Data, you take advantage of an NSFetchedResultsController, which you set up with NSSortDescriptor types to maintain a collection of NSManagedObjects organised by index paths in the same fashion as a UITableView, by section and row. A sort descriptor usually uses a property of the NSManagedObjects, or a computed property of them.

Am I understanding correctly, that you have an array of folders and you want the Core Data records in the same order as the folders? If so, do the folders have - or could you give them - some kind of unique, Comparable identifying property which each NSManagedObject could also be given, and use that property in your sort descriptors?

I hope my reply makes sense to you. Is that helpful?