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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:11:43+00:00 2026-06-02T19:11:43+00:00

I have an issue where I’m getting bad access exceptions but only when running

  • 0

I have an issue where I’m getting bad access exceptions but only when running a testing build (calling the same methods in a debug build doesn’t cause the problem to come up). The project has ARC enabled and I’m running this on the iPad 5.1 simulator using Xcode 4.3:

Here’s where the problem crops up:

- (void)testChangeFoodNotification {
    Player* p = [[Player alloc] init];
    [p addObserver:self forKeyPath:@"food" options:0 context:0]; // <-EXC_BAD_ACCESS (code=2)
    p.food += 1;
    STAssertTrue(_wasNotifiedOfFoodChange, nil);
}

At the point when the addObserver: method is called it doesn’t seem like any of the objects involved should have been released so what could be causing the exception?

EDIT:

Apologies if it wasn’t clear but the code above is being executed as part of a test case (using the standard Xcode OCUnit). Also in case it clarifies anything here’s the relevant code from the player class (there’s other ivars and methods but they don’t have any connection to the property or methods being tested):

// Public interface
@interface Player : NSObject

@property (nonatomic, assign) NSInteger food;

@end

// Private interface
@interface Player() {
    NSInteger _food;
}

@end

@implementation Player

@synthesize food = _food;

#pragma mark - Getters/Setters

- (void)setFood:(NSInteger)food {
    [self willChangeValueForKey:@"food"];
    _food = food;
    [self didChangeValueForKey:@"food"];    
}
  • 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-02T19:11:45+00:00Added an answer on June 2, 2026 at 7:11 pm

    If your class is indeed key-value compliant, ensure that the implementation for the class exhibiting the issue is not included in your test product. This means that the Target Membership panel of the Identity inspector for your .m file should only have your app checked (not YourAppTests).

    I experienced the same issue in Xcode 4.3.1 when an implementation was included in both products and I registered observers in both production and test code. The following logs tipped me off:

    Class YourClass is implemented in both /Users/yourUser/Library/Application Support/iPhone Simulator/5.1/Applications//YourApp.app/YourApp and /Users/yourUser/Library/Developer/Xcode/DerivedData/YourApp-/Build/Products/Debug-iphonesimulator/YourAppTests.octest/YourAppTests. One of the two will be used. Which one is undefined.

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

Sidebar

Related Questions

Have another issue here. Our app starts out with a tab activity. But, before
I have issue running cmake on a package residing in a mounted folder. I
I have an issue that I've spent hours trying to figure out, but since
We have an issue related to a Java application running under a (rather old)
I have issue with canceling Ajax Request. Our application interface is build in RF.
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
We are new to ROR, We have issue in creating Login/Logout process in ROR
Share your ideas please! I have issue to check the folder and convert a
I have an issue with an open source C++ project that I have been
I have an issue. One of my JS scripts needs Facebook SDK and Twitter

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.