How to automatically delete oldest core data entries when reach 50 entry limit?

后端 未结 2 1600
不知归路
不知归路 2020-12-31 23:48

What I\'m trying to accomplish is the following: I need to limit the amount of core data entries to 50. So if the user enters their 50th entry then the app would delete the

2条回答
  •  轮回少年
    2021-01-01 00:34

    OK, that's fine. CoreData is not going to do this for you, but you can do it yourself.

    You can retrieve objects from you context using an NSFetchRequest, and you can delete them using -[NSManagedObjectContext deleteObject:]. You can sort them using NSSortDescriptor objects.

提交回复
热议问题