Could someone give some guidance on how to prepend newly ingested data to Core Data in the correct index order?
I have Core Data with an attribute,
5, 4, 3, 2, 1, 0
5, 4, 3, 2, 1, 0, 7, 6
6, 7, 5, 4, 3, 2, 1, 0
In general, you should not concern yourself with the order in which objects are written to or stored in the database. Instead, specify the sort order in which you wish to receive the data when you fetch it from the database.
The sort order for a fetch is determined by the
sortDescriptors property of the
NSSortDescriptor specifies the key to determine the order, and whether the results should be in ascending order (v. descending).
So when you perform a fetch, you should in your case specify:
let sort = NSSortDescriptor(key:"contentID", ascending:false) fetchRequest.sortDescriptors = [sort] let fetchedResults = managedObjectContent.executeFetchRequest(fetchRequest, error: &error) as? [NSManagedObject]