Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:54:52+00:00 2026-06-06T06:54:52+00:00

I’m trying to follow the steps found here on comparing two arrays, and knowing

  • 0

I’m trying to follow the steps found here on comparing two arrays, and knowing when to create a new object, but I just don’t understand how it works:

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:

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.

Regardless of how many IDs you pass in, you only execute a single
fetch, and the rest is just walking the result set.

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.

I don’t understand how this works. I’m having trouble translating this to code:

for (int i =0;i<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;
    }
}

I don’t see how that would work? What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:54:55+00:00Added an answer on June 6, 2026 at 6:54 am

    Try something like this:

    //Employee.h
    @property (nonatomic) NSInteger ID;
    @property (nonatomic, strong) NSString *name;
    
    //Employee.m
    @synthesize ID, name;
    
    
    
    //Place where you put algorithm
    #import "Employee.h"
    ------------------------
    NSMutableArray *employeeIDs = [NSArray arrayWithObjects:[NSNumber numberWithInt:123], [NSNumber numberWithInt:456], [NSNumber numberWithInt:789], nil];
    
    //Creates employee objects
    Employee *employee1 = [[Employee alloc] init];
    employee1.ID = 123;
    employee1.name = @"John Smith";
    
    Employee *employee2 = [[Employee alloc] init];
    employee2.ID = 456;
    employee2.name = @"Bob Day";
    
    Employee *employee3 = [[Employee alloc] init];
    employee3.ID = 789;
    employee3.name = @"Steve Jobs";
    
    NSMutableArray *employeesArray = [NSArray arrayWithObjects:employee1, employee2, employee3, nil];
    
    for (int index = 0; index <= [employeeIDs count]; index++) {
    
        for(id currentEmployee in employeesArray){
    
            if(currentEmployee.ID != currentID){
    
                Employee *newEmployee = [[Employee alloc] init];
                newEmployee.name = [NSString stringWithFormat:@"Employee Name"];
                newEmployee.ID = 384;
    
                [employeeIDs addObject:[NSNumber numberWithInteger:newEmployee.ID]];
                [employees addObject:newEmployee.name];
    
            }
        }
    }
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.