What Cocoa/Core Foundation helper functions do you wish you knew about 2 years ago?

I've found NSStringFrom*() helpful when logging structs like CGRect, CGPoint, etc.

You can find a comprehensive overview at Apple's Foundation Functions Reference (Wayback Machine link).


Helper function to draw three part images with left cap, fill and right cap. Ideal for custom buttons

void NSDrawThreePartImage(NSRect frame,
    NSImage *startCap,
    NSImage *centerFill,
    NSImage *endCap,
    BOOL vertical,
    NSCompositingOperation op,
    CGFloat alphaFraction,
    BOOL flipped
);

Also look for NSDrawNinePartImage


This is one that I wish I had known about 6 months ago. I was creating our first iPhone application and I wanted to create a simple help file that was based on HTML using the UIWebView Controller.

However I could not figure out how to embed local images that I had stored in the Bundle and I did not want the user to have to have internet access to fetch the images from a server.

Little did I know I could do the following to get images from the Main Bundle

NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSURL *bundleBaseURL = [NSURL fileURLWithPath: bundlePath];

[webView loadHTMLString:htmlContent baseURL: bundleBaseURL];

The Image in your HTML can then call local images directly.

<img src="yourImageFromTheMainBundle.jpg" />

I had no idea I could set the baseURL with the location of the Bundle.