objective-ccustomizationnstoolbar

NSToolbar customization not available


ALL,

According to the documentation the property is available since macOS 10.4.

I'm on High Sierra 10.13 and getting an error:

../src/osx/cocoa/toolbar.mm:465:15: warning: instance method '-allowsUserCustomization:' not found (return type defaults to 'id')
      [-Wobjc-method-access]
        [self allowsUserCustomization:YES];
              ^~~~~~~~~~~~~~~~~~~~~~~
../src/osx/cocoa/toolbar.mm:339:12: note: receiver is instance of class declared here
@interface wxNSToolbar : NSToolbar
           ^
../src/osx/cocoa/toolbar.mm:466:15: warning: instance method '-autosaveConfiguration:' not found (return type defaults to 'id')
      [-Wobjc-method-access]
        [self autosaveConfiguration:YES];
              ^~~~~~~~~~~~~~~~~~~~~
../src/osx/cocoa/toolbar.mm:339:12: note: receiver is instance of class declared here
@interface wxNSToolbar : NSToolbar
           ^

Could someone please explain what is going on?

TIA!!

[EDIT]

I made a following implementation:

- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
    auto array = [NSArray arrayWithObjects:&m_default[0] count:m_default.size()];;
    return [NSArray arrayWithObjects:&m_default[0] count:m_default.size()];;
}

- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
    auto array = [NSArray arrayWithObjects:&m_allowed[0] count:m_allowed.size()];;
    return [NSArray arrayWithObjects:&m_allowed[0] count:m_allowed.size()];;
}

However, after executing the line auto array = ..., program crashes.

The variables m_allowed and m_default are of the type std::vector.

The vectors do have elements in them. Running under lldb I can see their content.

What am I doing wrong?


Solution

  • Setting a property in Objective-C:

    self.allowsUserCustomization = YES;
    

    Using the setter method:

    [self setAllowsUserCustomization:YES];