Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic array comparison algorithm
    primarykey
    data
    text
    <p>I'm trying to follow the <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/Articles/cdImporting.html" rel="nofollow">steps found here</a> on comparing two arrays, and knowing when to create a new object, but I just don't understand how it works:</p> <blockquote> <p>You end up with two sorted arrays—one with the employee IDs passed into the fetch request, and one with the managed objects that matched them. To process them, you walk the sorted lists following these steps:</p> </blockquote> <pre><code>Get the next ID and Employee. If the ID doesn't match the Employee ID, create a new Employee for that ID. Get the next Employee: if the IDs match, move to the next ID and Employee. </code></pre> <blockquote> <p>Regardless of how many IDs you pass in, you only execute a single fetch, and the rest is just walking the result set.</p> </blockquote> <p>Basically what's happening is I have an array of object ids from an external source, and the client system only has a subset of the objects represented by these ids. I need to figure out which objects I already have, and if I don't have them, create them, one by one.</p> <p>I don't understand how this works. I'm having trouble translating this to code:</p> <pre><code>for (int i =0;i&lt;ids.count;i++) { currentId = [ids objectAtIndex:i]; currentObject = [objects objectAtIndex:i]; if(currentObject.id != currentId) { //create new object } //"get the next employee" //uh what? nextEmployee = [objects objectAtIndex:i+1]; //? if(nextEmployee.id == currentId) { //"move on to the next id" continue; } } </code></pre> <p>I don't see how that would work? What am I missing?</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.
 

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