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 6379033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:05:10+00:00 2026-05-25T02:05:10+00:00

I have a problem with core data when setting relationships: The code below crashes

  • 0

I have a problem with core data when setting relationships:

The code below crashes randomly when setting the relationships between country and region.

If I disable the second for-loop, the method completes without errors.
Everything happens within the context living on the background-thread.

Again: I can create the objects for the regions and countries without trouble and they show up in the Simulators database just fine – but as soon as I try to set the relationships between then, the app crashes randomly.

Any thoughts ?

for (Region* region in regions) {        
    // only store if region code isn't empty
    if (region.m_RegionCode != nil && [region.m_RegionCode length] > 0) { 
        NSManagedObject* cdRegion = [NSEntityDescription insertNewObjectForEntityForName:CDREGION inManagedObjectContext:self.objectContextBackground];
        [cdRegion setValue:region.m_RegionCode forKey:@"code"];
        [cdRegion setValue:region.m_regioncodedescription forKey:@"name"];            
    }            
}
[self saveBackgroundContext];
 for (Region* region in regions) {        
    if (region.m_RegionCode != nil && [region.m_RegionCode length] > 0) { 
        NSManagedObject* cdRegion = [self getManagedObject:CDREGION withCode:region.m_RegionCode];
        NSManagedObject* CDCountry = [self getManagedObject:CDCOUNTRY withCode:region.m_countrycode];
        [cdRegion setValue:CDCountry forKey:@"country"];

    }            
}
  • 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-05-25T02:05:11+00:00Added an answer on May 25, 2026 at 2:05 am

    well – just to let you know: it actually was the problem (I know – it is listed on top of all pages regarding this topic 🙂 that I used a context between threads.

    I mixed up queues and threads. I created a single background-queue where I used my “background-context” … but of course i created several threads within that, who where interacting with the context… so…

    btw: it was this excellent article that finally clarified it for me:
    (came right in time 🙂
    http://www.cimgf.com/2011/08/22/importing-and-displaying-large-data-sets-in-core-data/

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

Sidebar

Related Questions

I have a problem with Core Data. The problem happens with this scenario :
I have a problem with my core data. I am trying to save the
I have a problem after the data being fetched from Core Data. I filled
I have a strange problem in my Core Data app. I have three entities
Hi I do have a problem with my Core Data storage! I delete it
Here's the core problem: I have a .NET application that is using COM interop
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem when I try insert some data to Informix TEXT column via
I am setting up unit testing for my core data app. I'm running into
I have a class that retrieves data from core data and stores it into

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.