Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That error generally relates to using a managed object incorrectly context across different threads or queues. You created the MOC on the main queue, but you're using it on a background queue without considering that fact. It's not <em>wrong</em> to use the MOC on a background queue, but you need to be aware of that and take preparations.</p> <p>You didn't say how you're creating the MOC. I suggest that you <em>should</em> be doing this:</p> <pre><code>NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType: NSMainQueueConcurrencyType]; </code></pre> <p>With main queue concurrency you can just use it normally on the main thread. When you're in your dispatch queue though, do this:</p> <pre><code>[context performBlockAndWait:^{ NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([self class])]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"coa == %@",coaStr]; request.predicate = predicate; NSArray *results = [context executeFetchRequest:request error:nil]; // ... }]; </code></pre> <p>This will ensure that the MOC's work occurs on the main thread even though you're on a background queue. (Technically what it actually means is that the MOC's work in the background will be correctly synchronized with work it does on the main queue, but the result is the same: this is the safe way to do this).</p> <p>A similar approach would be to use <code>NSPrivateQueueConcurrencyType</code> instead. If you do that, you'd use <code>performBlock</code> or <code>performBlockAndWait</code> everywhere for the MOC, not just on background threads.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload