Retrieving master data in insertion order

Is there an internal identification variable or timestamp that I can use in NSSortDescriptor to retrieve Core Data objects in the order in which they were inserted?

I would prefer not to create such properties if there is a cleaner way, although obviously this will do if there are no other alternatives.

+3
source share
2 answers

No, if you need a sort order for your data, you need to add this to your objects yourself. However, you can easily add the NSDate attribute, which has a default value of "NOW" so that it automatically populates.

+6

, "sortNum", , , .

1

, "displayOrder"

Master Data: Add Sort Order

2

.

 let insertAt = 0
 managedContextVar.insert(mngdObjectVar, atIndex: insertAt )

3

.

func updateDisplayOrder() {
    for i in 0..<taskList_Cntxt.count {
        let task = taskList_Cntxt[i]
        task.setValue( i, forKey: "displayOrder" )
    }
}

!

4

, , , , .

   let sortDescriptor = NSSortDescriptor(key: "displayOrder", ascending: true )

!

. , , , 95% . , .

.

+1

Source: https://habr.com/ru/post/1742653/


All Articles