Archive for the 'Cocoa' Category

Retain/Autorelease in Cocoa Getters

Someone asked me: “Why do some getters do:

- (id)object;
{
    return _object;
}

and others do:

- (id)object;
{
    return [[_object retain] autorelease];
}

…?”

The difference comes up in a special case which can cause a crash.
Read more »

AGShelfView – Mail-esque Split view

Mail and many other programs have been using this new kind of split view for a long while now. It typically has a main content area on the right side and a long table or outline view on the left side with a strip of a handful of buttons to add a new object, perform actions on it, and whatever else. Here’s an example of it seen in Araelium Edit:

AGShelfViewInAE

Writing the code to create this kind of view is fairly trivial if you know what you’re doing, but why bother reinventing the wheel? I give you AGShelfView.

Read more »

AGSidebarView Example

This is an example of how to put together a “Sidebar” like list. Mainly it demonstrates how to make top-level group rows taller than other rows so as to add padding between the groups, while keeping the custom-drawn outline cell (the reveal triangle) properly aligned. Download the project.

AGSidebarView Screenshot

Useful Nib Category Methods

If you’re loading a nib in your code that has a File’s Owner other than NSWindowController (or a subclass), then you (hopefully!) know that you need to release every top level object in the nib. If you use + [NSBundle loadNibNamed:owner:] then you need to create outlets to each of the top level objects, and release them when File’s Owner gets released.

That works fine and dandy if you do it, but if you forget to release a newly-added top level object, or forget to add an outlet to it so that you can release, you’ll leak memory. (That’s bad.) Is there an easy solution? You bet.

Read more »

Live Resizable Date Columns

If you pay attention to little details like I do, you’ll proabably be annoyed by date columns in table and outline views not live resizing. There are some somewhat obvious solutions but they can either be slow or the still don’t have the fluidity you’re looking for. Here’s a pretty simple solution.

Read more »

Talking to iChat

The InstantMessaging framework in 10.4 is useful for getting a list of all of your buddies and getting their email address, picture, or capabilities etc, but how can you send a file to a buddy? What about getting a list of the groups a buddy is in, or even simply creating a new chat window? The IM framework doesn’t do these things. You can do some of these through Applescript of course, but I’d rather gag on the proverbial fork.

So what can you do? Well, after poking around for a short while, I figured out (it’s not that hard) there’s a connection between iChat and another program called iChatAgent. iChat controls most everything dealing with service connections, buddies, and all of that by telling iChatAgent to do it. The iChat status menu item is separate from iChat.app and talks to iChatAgent also. This is why iChat.app doesn’t have to be open and you can still be connected to AIM or Jabber or whatnot. So how can you talk to iChatAgent directly? You do so by creating a connection to it using NSConnection.

Read more »