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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:20:58+00:00 2026-06-14T15:20:58+00:00

I am trying to understand iOS Core data transient properties and am having trouble

  • 0

I am trying to understand iOS Core data transient properties and am having trouble understanding some behavior.

Setup

I have two contexts a Main and a Private context. I call them mainContext and threadedContext .

The threaded context is the parent context and the main context is the child context. (I did it this way because my threaded context alters the model far more frequently than my main thread and UI do.

I have transient properties who’s value I need to pass through contexts.

I find that sometimes I loose the value and sometimes I don’t depending on how I run things.

Sample

This code has been simplified to show the problem. I have a Person object. The Person object has a transient entity called “other” of which you will see I assign an Other object to it that has a couple simple properties, nothing more.

- (void)case1
{

NSManagedObjectContext *mainThreadContext = [AppDelegate appDelegate].mainThreadContext;
NSManagedObjectContext *threadedContext = [AppDelegate appDelegate].threadedContext;

__block NSManagedObjectID *objectID = nil;

[mainThreadContext performBlockAndWait:^{
    //create
    Person *aPerson = [self createAPersonOnContext:mainThreadContext];

    //setup
    Other *other = [[Other alloc] init];

    aPerson.other = other;

    aPerson.other.favoriteColor = @"Blue";
    aPerson.other.city = @"Provo";

    //save
    NSError *error = nil;
    [mainThreadContext save:&error];

    objectID = aPerson.objectID;

    NSLog(@"%@",aPerson);

}];    
}

When I retrieve the Object like this the person.other property is still set (note that I am saving AFTER I retrieve the object:

[threadedContext performBlockAndWait:^{
    Person *aPerson = [self getPersonOnContext:threadedContext withID:objectID];

    NSError *threadedError = nil;
    [threadedContext save:&threadedError];

    NSLog(@"threaded %@", aPerson);
}];

When I retrieve the Object like this the person.other is no longer set (note that I am saving BEFORE I retrieve the object)

[threadedContext performBlockAndWait:^{

    NSError *threadedError = nil;
    [threadedContext save:&threadedError];

    Person *aPerson = [self getPersonOnContext:threadedContext withID:objectID];

    NSLog(@"threaded %@", aPerson);
}];

I’ve tried different things including refreshObject:mergChanges:
I’ve tried to watch when objects fault but that didn’t appear to be helpful.
Are transient values stored in a given context (assuming I have saved, or maybe not given the issue I am seeing) even if no model object is currently instantiated?

For those who feel they need more…
The method getPersonOnContext:WithID looks like this:

- (Person *)getPersonOnContext:(NSManagedObjectContext *)context withID:(NSManagedObjectID *)ID
{
    __block Person *person = nil;
    [context performBlockAndWait:^{
        person = (Person *)[context objectWithID:ID];
    }];
    return person;
} 

The createAPersonOnContext: looks like this:

- (Person *)createAPersonOnContext:(NSManagedObjectContext *)context
{
    __block Person *person = nil;
    [context performBlockAndWait:^{
        person = (Person *)[NSEntityDescription insertNewObjectForEntityForName:@"Person"
                                                         inManagedObjectContext:context];
        person.firstName = @"matt";
        person.lastName = @"ZZZ";
    }];
    return person;
}

I just wanted to hide this code to help bring attention to the problem it self.

If you want to experiment with this I have it on github: https://github.com/mcmurrym/CoreDataBehaviors

Update:

It appears that when I save before using the ID to retrieve the object in the threaded context that it is faulting the Person object which destroys the transient values. If I retrieve the object in the threaded context before saving, the transient value is preserved because the object is not faulted.

  • 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-14T15:20:59+00:00Added an answer on June 14, 2026 at 3:20 pm

    maxpower,

    Transients are quite simple. They are properties that are always non-existent in the backing store. Hence, the fact that you ever see them is because you are using a child MOC and have externally assigned those values. To ensure that a transient is always valid, you need to consider implementing the -awakeFromInsert, -awakeFromFetch, -prepareForDeletion, -didTurnIntoFault and -willTurnIntoFault methods.

    Andrew

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

Sidebar

Related Questions

I'm a beginner iOS/ObjectiveC coder and am trying to understand some details rather than
I'm trying to understand an issue I'm having with an iOS Universal app. I
I am trying to implement core data entities in a multi-threaded environment. I understand
I am trying to understand how to use blocks on iOS. I have read
I'm been trying to understand some of the nuances of the iOS system and
I'm trying to understand how view animations work in iOS; i currently have an
I am an iOS newbie and I am trying to understand some of the
I've been evaluating HTML5 audio on iOS 4 and have been trying to understand
I'm new to iOS development and I'm trying to understand if is it's possible
I am trying understand ViewModels deeper and I have read many articles and blogs

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.