English 中文(简体)
Core Data (iPhone)- Limiting the fetch results across a relationship
原标题:

I have recently been looking at Core Data for the iPhone and I have one query which I have not been able to find an answer to in the literature.

Lets imagine that I have a User model object with a to-many relationship with a Purchase object. A User may have thousands of purchases.

All of the information I have seen thus far seems to suggest that a fetch operation carried out across that relationship would return an NSSet with all of the Purchase objects associated with a particular User.

Clearly I would prefer if there was some way to limit the number of Purchase objects fetched by:

1) imposing some sort of criteria (e.g. only purchases over £1000 etc.); or

2) only fetching in batches if the above is not possible.

Is the above possible? I am just concerned that with the limited memory of the iPhone that I risk overloading it with thousands of unnecessarily fetched objects.

Thanks in advance for any replies.

最佳回答

My understanding is that when you fetch User objects, the relationship to its Purchase objects will be a fault that will only be loaded if accessed.
Instead, you could fetch Purchase objects with a predicate that specifies the User(s) and check(s) on any other criteria.

That said, I would definitely test realistic use cases (on devices) before spending too much time on performance issues. The efficiency of the iPhone and Core Data may surprise you.

问题回答
  1. Use a fetched property
  2. Use NSFetchedResultsController

The answer to these and the questions you will have next are answered in the Core Data Programming Guide for the iPhone.





相关问题
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风格的解决办法,只是一个简单的袖珍流程......

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

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

热门标签