advertisement

Article:
  Creating Toolbars for Mac OS X
Subject:   Small error in setupToolbar method
Date:   2004-07-13 14:00:39
From:   krishengreenwell
As mentioned here:


http://www.cocoadev.com/index.pl?NSToolbarSampleCode


...there's a small error with the provided setupToolbar method. The correct code is:


- (void)setupToolbar
{
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
[toolbar autorelease]; // wrong
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[mainWindow setToolbar:[toolbar autorelease]];
}


As you can see, there is a double autorelease, which is incorrect; it will cause the program to crash. The first autorelease call should be removed.


1 to 1 of 1
  1. Small error in setupToolbar method
    2004-07-13 14:07:24  krishengreenwell [View]

1 to 1 of 1