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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:40:18+00:00 2026-05-31T08:40:18+00:00

I am setting the value of a key in an NSDisctionary using this: –

  • 0

I am setting the value of a key in an NSDisctionary using this:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

NSLog(@"touchesEnded currentcolor: %@", currentColor);

if (currentTool == @"paint") {
NSLog(@"End Paint");
CGPoint point = [[touches anyObject] locationInView:self.view];
MaskPath * myNewPath = [mapView.drawthis containsPoint:point];
[myNewPath.attributes setValue:currentColor forKey:@"fill"];
[mapView setNeedsDisplay];

} else {
NSLog(@"End Pattern");

currentColor = @"1.png";

CGPoint point = [[touches anyObject] locationInView:self.view];
MaskPath * myNewPath = [mapView.drawthis containsPoint:point];
[myNewPath.attributes setValue:currentColor forKey:@"fill"];
[mapView setNeedsDisplay];
}
}

If I try to log the value of currentColor the app crashes with exc bad access (line 3)
If I take the Log out and go with the hardcoded value everything works fine. It also works fine with the first part of the if statement. I’ve checked the function that assigns currentColor and it is delivering the correct values. If I hard code the value of currentColor at that point it works fine. I’ve run the analyzer and I’ve got no memory leaks or issues. How else can I track this issue down?

  • 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-31T08:40:19+00:00Added an answer on May 31, 2026 at 8:40 am

    One glaring issue is that you are working with an autorelease variable as evidenced by your example. Most likely you are doing the same thing outside of that method.

    I recommend you make currentColor a property:

    @property (nonatomic, retain) NSString *currentColor;
    

    Then, to set it, you would do something like this:

    self.currentColor = @"SomeColor";
    

    Since you declared the currentColor property with a retain, you will not get a bad access when you pass it to your NSLog:

    NSLog(@"This is my color: %@", self.currentColor);
    

    If you already DO have a currentColor property and you are simply assigning the ivar, then you should be doing:

    currentColor = [NSString alloc] initWithString:@"Foo"];
    

    To sum it up:

    1. self.currentColor = @"Foo"; //<-This is automagically retained
    2. currentColor = [NSString alloc] initWithString:@"Foo"];  //<-Accessing the ivar directly, so you must ownify the string :D
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an user-defined Project setting (KEY/VALUE) like this: LATEST_BUILD_NUMBER 2.2.2.2 In my Info.plist,
In C, how to configure the initial settings for some program, using key-value pairs,
Does setting this value have the same effect as setting the debug=true in the
I am using jQuery UI Selectmenu and am having trouble setting the value of
This MESSED ME UP hard. I thought i was setting the key but i
I am starting out using key value observing, and the mutable array I'm observing
I have a model that looks like this and stores data as key-value pairs.
I would like to define a key & value in Settings.settings and bind the
Im setting a value in viewDidLoad so it can be a default settings, so
I am setting the value of a textbox via javascript client-side. When I refresh

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.