2

I use two persistent stores: first is read-only for default (built-in) app's data, second is read-write for user data. The issue occurs once user add any data in second store. In this case during execution of performFetch: method of NSFetchedResultsController I see the following message in debug console:

CoreData: error:  batched fetch request asked to fetch 1 objects but
received 2 objects as (
    "entity: Product; id: 0xd000000000340002 <x-coredata://A570FA00-5B60-4C21-A9B1-8A49C2AAC58B/Product/p13> ; data: <fault>)",
    "entity: Product; id: 0xd000000000340004 <x-coredata://84F31C0F-844D-44DD-BB2F-CC766BED8331/Product/p13> ; data: <fault>)"
)

It's clear for me that CoreData interprets the situation as error because last parts of Managed ObjectIDs are the same:

Product/p13

For some reason CoreData doesn't take in account that these objects are from different stores: A570FA00-5B60-4C21-A9B1-8A49C2AAC58B and 84F31C0F-844D-44DD-BB2F-CC766BED8331 correspondingly.

Except error message in console everything works correctly. But I would prefer not to see it. Does anybody have an idea of how to resolve such a different stores ObjectID's collision?

4
  • 1
    Do you need the fetch to search in both stores? If not then you could try using the affectedStores property of the fetch request for the FRC.
    – pbasdf
    Feb 28, 2016 at 23:41
  • Thank you for recommendation, but yes, I need to fetch data from both stores.
    – berec
    Feb 29, 2016 at 11:00
  • 2
    Are you using fetchBatchSize for the fetch? I believe in that case the FRC fetches all the objectIDs at first, then uses a subset of them to select a batch. Have you tried enabling SQLDebug to see better what's going on?
    – pbasdf
    Feb 29, 2016 at 21:27
  • 1
    Yes, I use fetchBatchSize for the sake of optimum memory usage. And you're right: as it turned out batching caused the error. SQLDebug doesn't show anything special. So it's obviously CoreData framework's error. More likely I will stop using fetchBatchSize in my particular case preferring clean debug console to optimization.
    – berec
    Mar 4, 2016 at 21:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy