BuySellAds.com

My book Barcodes with iOS 7 is nearing completion. Buy it now to get early access!
Our DNA is written in Objective-C
Jump

3 Mac Tidbits

Here are three small pieces that I discovered while working on my second major Mac app. It’s for internal use by a client, so I cannot tell you about it, but it is a great place for me to learn more about the various oddities you find when developing for the Mac platform.

Single-Window App

For an app that has only one window and that should quit when this is closed. Add this to your app delegate:

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
    return YES;
}

It’s as simple as that.

Toolbar not saving Configuration

If you have a toolbar then “Autosaves Configuration” is not checked by default. You need to enable this if you want the toolbar customizations to be automatically saved.

Enable Autosave on Toolbar

It’s now happened twice to me that a client complained about this. I wonder why this is not a default.

Edit Commands not Working on NSTextField

I had removed the Edit menu because I didn’t think that my app would need those. Turns out, you shouldn’t because the presence of these menu items also decides whether or not you can use edit commands on any NSTextField.

And you don’t just need the menu items, you also need to have them send actions down the responder chain. This is done by connecting them to the appropriate actions.

Connection made

 

That was also when I stumbled on a bug in Interface Builder, it does not show a redo: action. You can see and connect the Undo action, but Redo is just not there.

If you create a new Mac app this connection is made, but Interface Builder puts an exclamation mark next to it. If you remove this connection, for example by removing the Edit menu, then the action disappears.

redo: missing

As a workaround I created a custom redo: action to make the connection. Afterwards you can either leave the custom action in there, it does not seem to interfere, or remove it in which case you see the exclamation mark again.


Categories: Recipes

%d bloggers like this: