English 中文(简体)
如何在达到50个入门限制时自动删除最老的核心数据条目?
原标题:How to automatically delete oldest core data entries when reach 50 entry limit?

我想要做到的是: 我需要将核心数据条目的数量限制在50个。 因此,如果用户进入第50条条目,则该用户将删除最老的条目,并将新条目添加到顶端。 因此,如果用户永远不删除条目,如果核心数据有50个条目,那么当用户试图增加新的条目时,则该用户将删除最老的条目,并增加用户的新条目。 基本上,我试图有历史背景,但我不想让用户能够接过50个条目,然而,我希望他们在50个限制中能够增加新的条目,仅仅放弃最古老的条目,并增加最新的条目。 这样做的最容易的方法是什么? I m new to core data and with augh time Understanding a Much of it. 这里的法典/实例表明,我与我合作。 附录一 得到帮助。

最佳回答

请允许我说,有一个名为<代码>History的实体。 最容易的解决办法是添加一个<条码>,/code>,归属于贵实体。 然后使用<代码>History物体。

你们需要三个方面:

  1. The first one will fetch as faults all the existing History objects and then count them. If the count is <50, then just add the new History object and your done.
  2. If the count>=50, then do a fetch for specific value and use the @max or @min (I forget which for dates) collections operator to find the oldest creationDate. (As luck would have it the example at the link it pretty much exactly what you need.)
  3. Perform a fetch for the object with the creationDate returned by (2) and delete it.

然后添加新的历史目标。

问题回答

缩略语 核心捐款不会给你,但你可以这样做。

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.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签