Question Regarding the Memory Address of Objects
Question Regarding the Memory Address of Objects
- Subject: Question Regarding the Memory Address of Objects
- From: "Carter R. Harrison" <email@hidden>
- Date: Thu, 18 Dec 2008 14:57:59 -0500
Ok, hopefully this is an easy one.
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.
Any ideas? As always, thanks in advance.
_______________________________________________
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