Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>first off, can you explain what the purpose of doing the following is for: </p> <p>first you create a new context with a private concurrency type.</p> <pre><code>NSManagedObjectContext *context = [[NSManagedObjectContext alloc]initWithConcurrencyType:NSPrivateQueueConcurrencyType]; </code></pre> <p>Now you take that context and reassign it to something else?</p> <pre><code>context = [appDelegate managedObjectContext]; </code></pre> <p>Now the context that you are using is the one you defined in your appDelegate...</p> <p>Furthermore, assuming that the context defined in your appDelegate is correct, you are performing a fetch request in the context asynchronously. Then on the following lines you check for the results of that fetch without knowing whether or not the fetch request has been returned or not (since it is asynchronous). This explains why you see the results the second time since they have been fetched by then. A quick fix would be to sprinkle in some GCD into the context block like so:</p> <pre><code>[context performBlock:^{ NSError *error = nil; NSArray *fetchedObjects = [context executeFetchRequest:request error:&amp;error]; dispatch_async(dispatch_get_main_queue(),^{ _objects = fetchedObjects; if (_objects == nil) { _status.text = @"No matches"; } else { NSLog(@"data= %@", [_objects description]); NSManagedObject *matches = _objects[0]; _address.text = [matches valueForKey:@"address"]; _phone.text = [matches valueForKey:@"phone"]; _status.text = [NSString stringWithFormat: @"%d matches found", [_objects count]]; } }); }]; </code></pre> <p>I hope this helps?</p>
    singulars
    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. 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