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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:02:34+00:00 2026-05-30T14:02:34+00:00

Got a Stumper (at least for me). I am using iOS 5.0 w/ ARC,

  • 0

Got a Stumper (at least for me).

I am using iOS 5.0 w/ ARC, and Core Data inside of UIManagedDocument.

I have an Entity (Group) with a to-many relationship (called people) to entity (Person). When I add a new Group, and add then a new Person (setting the person’s .group relationship to the new group), I cannot retrieve the related people using a predicate on the Person entity where (“group == %@”, myGroup). I also tried using the Group’s addPerson setter.

If I shut down XCode simulator and rerun it, it recognizes the relationship that was created in the previous run, I can even add new people to the existing Group object. I just can’t add a new Group and then add people to without shutting down the Simulator (or device if I’m running on device) in order to see the relationship.

If I do a [group.people count], immediately after adding the new Group and a related Person, it gives me the correct number. But a fetch with a predicate doesn’t work until I restart the app.

It seems as if the managedObjectContext of the UIManagedDocument is not seeing the relationship. I’ve tried saving the context, saving context.parentContext, and saving the Document. None of that helped.

Any ideas would be appreciated!

  • 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-30T14:02:36+00:00Added an answer on May 30, 2026 at 2:02 pm

    A UIManagedDocument will save, well, basically, when it feels like it; you don’t have control as to when that occurs. It will, however, certainly save on application termination, which is why you see the inserts when you restart.

    As a result, while you may think you have permanent object ids, they’re actually likely temporary, and thus can’t be fetched. Simply dumping them via an NSLog would validate this, as temporary object ids show up as such when logged.

    To force them to be permanent and thus usable, try the following after performing your additions. Assuming you have a UIManagedDocument as an ivar:

    - (void)performUpdate
    {
        NSManagedObjectContext * context = self.managedDocument.managedObjectContext;
        NSSet                  * inserts = [context insertedObjects];
    
        if ([inserts count])
        {
            NSError * error = nil;
    
            if ([context obtainPermanentIDsForObjects:[inserts allObjects]
                                                error:&error] == NO)
            {
                NSLog(@"BAM! %@", error);
            }
        }
    
        [self.managedDocument updateChangeCount:UIDocumentChangeDone];
    }
    

    Obviously, you’d replace the error handling with something a bit better here. The UIManagedDocument will now save at some point in the future (again, you have absolutely no control over when that’ll happen, we’re just asking it to do so in the last line, in the same way that an undo manager would), but newly-inserted objects should now have usable permanent ids and fetches should work properly.

    And yes, this seems a bit odd to me too, but this appears to be the correct way to do things with a UIManagedDocument in play.

    Frankly, I’d love for someone to tell me I’m incorrect and provide a better solution.

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

Sidebar

Related Questions

I've been stumped with some SQL where I've got several rows of data, and
This one has got me stumped. I am currently rendering a form using ASP
This problem has got me stumped for a few days now. I have a
I am working on an iOS app and have been stumped for the last
Has anyone managed to use core-plot from wax? I have been trying recently, but
Ok so this is kind of got me stumped. I have two installs of
I'm trying to automate many repetitive tasks at work and this small problem got
I've got 3 tables representing Users, Roles, and the many-to-many UsersInRoles - with keys:
I have a collection of ZIP archives residing in a collection of folders inside
This one has really got me stumped. I have certain forms that are being

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.