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

  • SEARCH
  • Home
  • 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 7852749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:29:48+00:00 2026-06-02T19:29:48+00:00

I’ve run into a problem. Over the weekend I’ve been working on a project

  • 0

I’ve run into a problem.

Over the weekend I’ve been working on a project where I’m pulling a large xml from a webservice.

It basically has 3 tiers – Clients, Managers, Staff all hierarchical. So the first time the app runs, it pulls this xml and parses it and creates all the entries in the 3 releated Entities – Clients, Managers and Staff.

Every time the app launches I need to pull that same XML down, but this time, I only need to ‘update’ any of the existing records that have changed, or add new ones for new clients, managers or staff that have appeared since last time.

So – at the moment, as I said, it’s pulling it all, parsing it correctly and creating the correct entities and filling in all the attributes.

However, with no data change, on the 2nd launch it’s DUPLICATING all of the data – so instead of 15 clients ( the correct number ) I have 30 and so on…

Do I really have to add lots of code in my parsing to check that instead of creating a new NSManagedObject, I check if it’s already there?

And if it is – I have to then manually check every attribute?

That’s awfully painful and longwinded – isn’t there a way to make Core Data do this kinda stuff for me – automatically?

Thanks for any help or suggestions.

  • 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-02T19:29:50+00:00Added an answer on June 2, 2026 at 7:29 pm

    As Stated in Apple Docs https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdImporting.html

    You need to loop the data model and handle it from there like this

    Example:

    // loop over employeeIDs
    // anID = ... each employeeID in turn
    // within body of loop
    
    NSString *predicateString = [NSString stringWithFormat: @"employeeID == %@", anID];
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];
    

    Personally I do not like this method and I wrote this snippet of code that handles this in a pro-efficient manor and which is straight forward! I noticed with Apples method I ran into issues with strings having different characters such as capitol letters and spaces. Below code is tested and working if you rename all your corresponding objects correctly I honestly believe this is the most efficient way to accomplish not adding duplicates in core data.

    -(void)AvoidDuplicatesinDataModel
    {
        // Define our table/entity to use
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Users"
                                                  inManagedObjectContext:managedObjectContext];
    
        // Setup the fetch request
        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        [request setEntity:entity];
    
        // Define how we will sort the records
        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"users"
                                                                       ascending:NO];
        NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    
        [request setSortDescriptors:sortDescriptors];
        [sortDescriptor release];
    
        // Fetch the records and handle an error
        NSError *Fetcherror;
        NSMutableArray *mutableFetchResults = [[managedObjectContext
                                                executeFetchRequest:request error:&Fetcherror] mutableCopy];
    
        if (!mutableFetchResults) {
            // Handle the error.
            // This is a serious error
        }
    
        //here usersNameTextField.text can be any (id) string that you are searching for
        if ([[mutableFetchResults valueForKey:@"users"]
             containsObject:usernameTextField.text]) {
            //Alert user or handle your duplicate methods from here
            return;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words

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.