• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question Regarding the Memory Address of Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question Regarding the Memory Address of Objects


  • Subject: Re: Question Regarding the Memory Address of Objects
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 18 Dec 2008 12:36:42 -0800

On Dec 18, 2008, at 11:57, Carter R. Harrison wrote:

I have a Nib file setup with an NSView and some NSButton's as subviews of that view. I have IBOutlets for each of the NSButton's in my NSView subclass.

In the awakeFromNib: method of my NSView subclass I do the following:

- (void)awakeFromNib
{
//Initialize NSMutableDictionary instance variable
dict = [[NSMutableDictionary alloc] initWithCapacity:1]; // "dict" is an NSMutableDictionary instance variable


//Set the value "button1" into the dictionary and make it's key the string representation of button1's memory address.
[dict setValue:@"button1" forKey:[NSString stringWithFormat:@"%x", &button1]]; // "button1" is one of my IBOutlets.
}


When a user clicks the button the following method fires and promptly crashes my app.

- (void)buttonClicked:(id)sender
{
// Print out the value for the button pressed. THIS LINE CRASHES
NSString *value = [dict valueForKey:[NSString stringWithFormat:@"%x", &sender]];


	//This next line crashes app - EXC_BAD_ACCESS
	NSLog(@"Value is: %@", value);
}

It seems like the memory address of the sender is different than what it should be. I did some debugging and the address of the sender is always bfffe2e8 which really shouldn't be possible at all.

Don't use an "&" in either place. You don't want the address of the outlet or the address of a local variable on the stack, you want a pointer to the button, which is what you get without the &.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Question Regarding the Memory Address of Objects (From: "Carter R. Harrison" <email@hidden>)

  • Prev by Date: Re: Enabling add button
  • Next by Date: Re: Enabling add button
  • Previous by thread: Question Regarding the Memory Address of Objects
  • Next by thread: Re: Question Regarding the Memory Address of Objects
  • Index(es):
    • Date
    • Thread