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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:34:48+00:00 2026-06-18T19:34:48+00:00

My situation : Assuming I have a class Person (subclass of NSManagedObject). Everytime the

  • 0

My situation:
Assuming I have a class Person(subclass of NSManagedObject). Everytime the user clicks on a button a new Person instance will be created and added to a global NSMutableArray. Also the new created Person instance will be added to child context, like this way:

NSManagedObjectContext *childContext = [[NSManagedObjectContext alloc] initWithConcurrencyType: NSPrivateConcurrencyType];
[childContext setParentContext: _mainContext];

Also when clicking the button I save the context: (it is a little bit more complicated, but follows this structure)

[childContext performBlock:^{
    [childContext save:nil];
    [_mainContext save:nil];
}];

After clicking two or more times (not sure if it depends on the total clicks) on the button objects in my array becomes fault.

According to the docs: Accessing a property of a fault object should load the persistent object.
Even when I am accessing a property of my NSManagedObject the object is still fault and property is nil.

Why are objects fault in my array and how do I access a property of a fault object?

Edit:

When loading the UIViewController I’m fetching all existing objects from the datastore:

-(NSArray*)fetchPersons {
    NSManagedObjectContext *context = [self managedObjectContext]; //this is _mainContext, it is created with initWithConcurrencyType:NSMainQueueConcurrencyType
    NSFetchRequest  *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *description = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
    [fetchRequest setEntity:description];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"key = %i", aCondition];
    [fetchRequest setPredicate:predicate];
    return [context executeFetchRequest:fetchRequest error:nil];
}

I’m using this NSArray from fetchPersons to populate the NSMutableArray.

Creating a new Person object:

-(Person*)createPerson {
    NSManagedObjectContext *childContext = [[NSManagedObjectContext alloc] initWithConcurrencyType: NSPrivateQueueConcurrencyType]; 
    [childContext setParentContext:[self managedObjectContext]];
    Person *person = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:childContext];
    return person;
} 

I’m not sure how to handle the objects with the òbjectID`.
I’m using the childContext as a temporary context. Sometimes I need a Person instance, but I don’t want to save it to the persistent store (or insert it to the main context at the beginning).

After all these steps I have all objects in my NSMutableArray. I get nil properties (fault object) after creating some objects and try to log their attributes (person.name or something).

  • 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-18T19:34:49+00:00Added an answer on June 18, 2026 at 7:34 pm

    NSManagedObjects retain a tight relationship with the NSManagedObjectContext on which they were created. The specific reasons for this are that managed objects are always mutable, so may need to write back to the store, and there’s an expectation of future faulting — Core Data explicitly may choose not to load the whole persistent store into memory but may have to deal with your future arbitrary traversal of the object graph or with low memory warnings.

    (aside: this is also the most proximate reason why Core Data objects can’t be used on anything other than the thread/queue that they were created on; it’s the contexts and the various bits of implicit communication between contexts and objects that aren’t safe)

    What that means in practice is that you should’t allow a managed object to outlive its store.

    To allow you to send objects back and forth between different agents with different contexts, Apple implements the NSManagedObjectID which is a unique identifier for any managed object. It’s a fully opaque class but, for information, if you have a SQLite store then it’s a reference to the relevant table and row; if you have one of the other store types then it’s similarly a pointer to a location in the store. It carries none of the object data itself.

    So what you’d normally do is call objectID on an object while the context it was created under is still alive. You can then pass that over to whoever else wants it. They’ll then use [myManagedObjectContext -existingObjectWithID:error:] to get a new copy of the managed object that they can use safely. The new copy will be bound to that context rather than to the original so will be safe whenever and for however long that context is safe, rather than the original.

    The only potential surprise is that when you first insert an object, it gets only a temporary object ID. That’s because Core Data likes to batch up things that will need inserting into the store and then insert them all at once only when you request a save.

    For your purposes you don’t want to pass the ID up until after a save anyway because the object won’t exist in the parent store. So the point is partly academic but supposing you wanted to ferret away the IDs for some other reason, you might also consider using the context’s -obtainPermanentIDsForObjects:error:, which can be a lot faster than the actual save, depending on your store type, and will definitely never be slower.

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

Sidebar

Related Questions

I'm new to NHibernate and Fluent NHibernate. Assuming I have a situation like the
I have the following situation. Assuming there are 3 systems: A,B,C and A is
I occasionally find myself in a situation where I have a variable that will
Assuming I have the following I wish to unit test: class Foo: IAMethods, IBMethods
Assuming defintion: case class IntegerWrapper(i : Int) and being in a situation that potentially
I have a situation where a class holds a vector of constant size 5.
Situation: I have an index page which loads pages into it with ajax as
Situation: I have some persons with certain skills and they can/might belong to more
The following method op belongs to a class with two private integer-valued instance variables,
The problem: class StatesChain : IState, IHasStateList { private TasksChain tasks = new TasksChain();

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.