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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:49:01+00:00 2026-05-18T06:49:01+00:00

I have a subclass of NSManagedObject Class used with Core Data in iPhone. However,

  • 0

I have a subclass of NSManagedObject Class used with Core Data in iPhone. However, I have a temporary “field” (ivar) that I want to add in that Class (but I dont want to persist it in the data-store). Tried to use informal and formal protocol, but both of them give me a “static-variable” like behaviour. (It behaves like a Class Variable rather than Instance Variable). Any suggestion?

My first attempt, created Test “Dummy-class” which is supposedly a subclass of NSManagedObject, then I created Test-category

@interface Test (custom)
   NSString *_string  ;
  - (void)setString:(NSString *)newString;  
  - (NSString *)string;
@end

Those are the usual setter and getter. This is the way I use the Test class

Test *a = [[Test alloc] init];  
Test *b = [[Test alloc] init];  
[a setString:@"Test1"];  
NSLog(@"%@", [a string]);         //This will print out Test1

[b setString:@"Test2"];          
NSLog(@"%@", [b string]);         //This will print out Test2         
NSLog(@"%@", [a string]);         //Unfortunately, this will also print out Test2

I could also mess with the NSManagedObject subclass (which is my Entity) directly but I dont think that is the way to do it.

  • 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-18T06:49:02+00:00Added an answer on May 18, 2026 at 6:49 am

    You can’t add an instance variable in the (in)formal protocol or in the category.

    Any variable definition inside the category is treated as a variable definition at the file level outside the category, so it behaves like a class variable. It’s a confusing behavior; I guess the compiler should warn about it.

    The standard solution is to add the ivar which holds transient data (which does not persist in the database) in the subclass representing the entity directly, as in:

    @interface MyEntity:NSManagedObject{
           NSString*stringHoldingTransientSomething;
    }
          ...
    @end
    

    and then specifying MyEntity as the class in the Core Data Editor. Note that Core Data does not automatically save ivars in your custom NSManagedObject subclass; it only saves the properties specified in the Core Data model. So you can add as many book-keeping ivars as you want in your custom subclass.

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

Sidebar

Related Questions

I have an Offer class (NSManagedObject subclass) that I want to use to handle
I have a ConfiguracaoDaApp class in my project that is a NSManagedObject subclass. I
I have a NSManagedObject subclass, created by the XCode model interface. This class has
In my Objective-C project I have a Country class (NSManagedObject subclass). When comparing a
I have a CoreData NSManagedObject subclass, TextNarration, that has an attribute of type NSString,
I have several core data entities that contains a bunch of empty NSString properties.
I have a subclass of NSWindowController that has its own nib and another class
I have a subclass s of UIView. I want to put some buttons and
I have a subclass with an over-ridden method that I know always returns a
If I have a subclass that has yet to implement a function provided by

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.