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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:55:52+00:00 2026-05-22T20:55:52+00:00

I am getting the EXC_BAD_ACCESS error when trying to set a value inside a

  • 0

I am getting the EXC_BAD_ACCESS error when trying to set a value inside a subclass of NSManagedObject for the second time.

I am using zombies but nothing is showing up in the console. Printing out the object using GDB I see that the object has the same memory address both times I try to set the value – not sure why though.

Situation:

  1. I have a view (A) that, when a QR code is scanned, adds a subview (B) which in turn downloads XML that is then saved into a subclassed NSManagedObject.
  2. Inside the subview (B) I navigate back (removeFromSuperView is called)
  3. Back in the original view (A)
  4. Next time, when the same QR code is scanned, it (A) finds the NSManagedObject from the database and attaches that to an instance variable on a new view (same type as B) that it then adds as a subview to the original (A).

In view B’s viewDidLoad i always try to set the current date in order to track when a user “saw” that object. This is where I get the EXC_BAD_ACCESS error:

    self.currentPiece.piece_last_viewed = [[NSNumber alloc] initWithDouble:[[NSDate date] timeIntervalSince1970]];

Where self.currentPiece is the instance of a subclassed NSManagedObject that was attached in A when that object existed in the database.

I know that it is being released somewhere but I don’t know where since managed objects take care of much of that on their own. The error only occurs the second time around that I try to set the value.

I have tried to make this clear. Please tell me if you want me to clarify it even more.
Thanks for the help (have worked on this for some hours now)

UPDATE:

Declaring the piece_last_viewed in HubPiece.h:

@interface HubPiece : NSManagedObject {

}

// ...

@property (nonatomic, retain) NSNumber *piece_last_viewed;

HubPiece.m:

@dynamic piece_last_viewed;

//...inside init method:

self.piece_last_viewed = [[NSNumber alloc] initWithDouble:[[NSDate date] timeIntervalSince1970]];

UPDATE 2:

It is not due to the switching of subviews, that is ruled out. I then realized that I didn’t save my changes either, so I introduced save: inside the subclassed NSManagedObject. I then got an earlier error the first time I try to save the entity instance (which saved during an app session, but the data vanishes if I quit the app entirely and then open it up again). So I thought using [context save:&error] would be a good idea 🙂 …but now that doesn’t work and give me a EXC_BAD_ACCESS error.

The HubPiece itself is initialized from another class HubPieceView.m :

self.currentPiece = [[HubPiece alloc] initWithXML:pieceXML];

self.currentPiece is a class variable of type HubPiece and it first declared in .h file and then synthesized in .m file.

Then inside HubPiece.m the initializer looks like this:

-(id)initWithXML:(TBXMLElement *)pieceXML
{
    // Setup the environment for dealing with Core Data and managed objects
    HenryHubAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSEntityDescription *entityHubPiece = [NSEntityDescription entityForName:@"HubPiece" 
                                                      inManagedObjectContext:context];

    // STORING values
    self = [[HubPiece alloc] initWithEntity:entityHubPiece insertIntoManagedObjectContext:context];

    // ...setting variables with normal assignment: self.var = value;

    NSError *error;

    // Save fails
    if (![context save:&error] ){
        NSLog(@" ERROR: %@", [error localizedDescription]);
    }

    return self;
}
  • 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-22T20:55:53+00:00Added an answer on May 22, 2026 at 8:55 pm

    I just realized my problem. I had been assigning values to the entity through with normal ‘=’ assignment:

    self.currentPiece.piece_last_viewed = [[NSNumber alloc] initWithDouble:[[NSDate date] timeIntervalSince1970]];
    

    When it should have been done:

    [self setCurrentPiece.piece_last_viewed:[[NSNumber alloc] initWithDouble:[[NSDate date] timeIntervalSince1970]] ];
    

    This is because it is a managed object which creates it’s own accessors at runtime through the @dynamic compiler instruction.

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

Sidebar

Related Questions

I'm getting an error here that says I haven't defined a method, but it
Every time that I want to do a Layout, I'm getting a black layout
We manage a site for a medical charity. They have a number of links

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.