views:

67

answers:

1

Hi,

I'm trying to understand why:

NSLog(@"self = %p", self);

in awakeFromNib prints a different value than the same NSLog in viewDidLoad?

This isn't a huge problem because I don't need the awakeFromNib but I would like to understand how it works.

The code that creates the controller is the following:

    MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    myViewController.image = tmpImage;
    [self.navigationController pushViewController:myViewController animated:YES];
    [myViewController release];

Thanks for any advices!

A: 

Because when NSLog logs an object, it actually sends the - description message to the object. The address you are printing is actually the address of the returned NSString object containing the textual description of the instances. Since a new string is returned each time the message is sent, you get a different address.

If you want the address of the object you need to use:

NSLog(@"self = %p", &self);
TechZen
I also get different values.Also, the debugger gives me different values for the address of self (hovering over "self")
Kamchatka
Not sure then what is causing your problem but you where using the wrong form of the NSLog statement.
TechZen