NSFetchRequest without sort descriptors

We cannot use NSFetchRequest without providing NSSortDescriptor (s). All I want to do is get the results and show them in the order in which they were created. Is there a built-in way to do this ?, or do I need to create a new "auto-increment" field? (which contradicts everything that CoreData points to, in my opinion).

+5
source share
3 answers

Master data does not guarantee anything order. You do not need to create an "auto-increment" field; however, you can make the corresponding attribute. Since you obviously care about the creation date of something, you must add the dateCreated attribute to your data object. Then do the sorting.

You can easily set this in a managed object method didAwakeFromInsert.

+6
source

It looks like you are thinking about Core Data in terms of tables and expect that there should be an automatic order, like the row number of the table. However, Core Data does not use tables, rows, or any other fixed linear data structure.

, , . NSFetchRequest , , .

, . , , , . , Core Data , ?

, , , , , timestamp , .

+6
[[NSSortDescriptor alloc] initWithKey:@"" ascending:NO];

NSFetchRequest , , . "initWithKey:". .

0

All Articles