Build a Custom Sheet in Cocoa

blog — Tags: , , , , , — anon @ 10/03 7:51 pm

What is a sheet? Well, Cocoa introduced several new GUI elements like drawers that aren’t used by too many applications right now. They are used nicely, however, in Mail to house your mailboxes and in OmniWeb to store your bookmarks.

One of the elements that are available to Mac developers are called “sheets”. In particular, sheets are those things that slide out of the title bar of a window. In fact, a sheet is just a NSPanel that is being attached to the application window at runtime. You can see a sheet in action when actually opening or saving a file.

What is the difference between a sheet that slides out and a modal window that pops up? Well, there are some serious considerations. You may also want to check out this tutorial by Erik. J. Barzeski on CocoaDevCentral which I used as a informational and textual base for this post. There you can find a little bit more about modal windows which I don’t want to explain right here in depth.

In short, sheets are a very stylish way to let the user know that a certain action needs to be done or that there is something wrong and that need to be fixed.

(more…)

Hacking Cocoa: Method Swizzling

blog — Tags: , , , , , , , — anon @ 10/03 5:47 pm

From cocoadev.com:

The Objective-C runtime lets you modify the mappings from a selector (method name) to an implementation (the method code itself). This allows you to “patch” methods in code you don’t have the source to (AppKit, FoundationKit, etc).

Unlike creating a category method with the same name as the original method (effectively replacing the original method), MethodSwizzling lets your replacement method make use of the original method, almost like subclassing.

This is best used in cases where a single method needs substitution or extension but if you need to modify many behaviors of a class, you may be better off using ClassPosing.

But I found this article way more informative and that, in turn, led my way to the SIMBL Framework which I can greatly recommend.

After thinking about this a couple of minutes you’ll also find a huge amount of possibilities and hack-arounds. But seriously, there are some things to consider like this.

To make it short, Kevin Ballards code did fail in the 10.5 Mac OS X release and had to be rewritten. In fact, many code had to be rewritten which somehow led to JRSwizzle, a very good implementation that runs under Leopard and Snow Leopard.

So either using SIMBL or MethodSwizzling (JRSwizzle in particular) does the trick. It’s absolutely obvious to be very careful when swizzling methods or creating plugins via SIMBL – but the possibilities appear very clear and vast to me.

Another great possibility to hack around with Cocoa is F-Script by Philippe Mougin and F-ScriptAnywhere by Ken Ferry. Two very essential tools when hacking just for fun or seriously developing Cocoa applications.

copyright © 2008-2010 datenkompost.de/blog - barecity derivative | imprint
* a title remix inspired by a popular german book