Matt Gallagher: Cocoa with Love

Articles about Swift, Cocoa, software design and programming.

  • Nov 14, 2009

    Objective-C era

    A drop-in fix for the problems with NSHost

    As pointed out by Mike Ash in his recent Friday Q&A 2009-11-13: Dangerous Cocoa Calls, NSHost is not thread-safe for use outside of the main thread and due to potentially slow, synchronous network access is not really suitable for use on the main thread either. Fortunately, in Cocoa there are often ways to transparently fix classes that don't work as they should. In this post, I'll show you how you can transparently patch NSHost using a drop-in solution and provide a non-blocking solution for NSHost lookups.

    Read article

  • Nov 3, 2009

    Objective-C era

    Creating iPhone and Mac icons using Inkscape (Part 1 of 2)

    In this two part series, I'll give a beginner's guide to creating iPhone and Mac application icons using Inkscape — a free, vector illustration program. In this first part, I'll talk about the common styles and traits of icons on the Mac and iPhone and give a step-by-step guide to creating the first iPhone icon in Inkscape.

    Read article

  • Oct 25, 2009

    Objective-C era

    Memory and thread-safe custom property methods

    Objective-2.0 property methods are a nice convenience but if you need to override a property implementation — particularly an atomic, retained or copied object setter property — there are some potential bugs you can create if you don't follow the rules carefully. I'll show you the pitfalls and the correct way to implement a property accessor. I'll also show a way to directly invoke hidden runtime functions to let Objective-C perform atomic getting and setting safely for you.

    Read article

  • Oct 18, 2009

    Objective-C era

    How blocks are implemented (and the consequences)

    This post is a look at how clang implements blocks and how this implementation leads to a number of strange behaviors including local variables that end up global, Objective-C objects allocated on the stack instead of the heap, C variables that behave like C++ references, Objective-C objects in non-Objective-C languages, copy methods that don't copy and retain methods that don't retain.

    Read article

  • Oct 12, 2009

    Objective-C era

    Objective-C's niche: why it survives in a world of alternatives

    Objective-C remains an impediment for many programmers coming to the Mac or iPhone platforms — few programmers have ever experienced it before learning Cocoa, forcing two learning curves at once for new Cocoa developers. How did Apple end up with such a weird language? And for a company known to replace CPU architectures and their entire operating system, why does Apple persist with Objective-C? The answer lies in the methods.

    Read article

  • Oct 5, 2009

    Objective-C era

    The ugly side of blocks: explicit declarations and casting.

    Blocks are a welcome addition to C/Objective-C/C++/Objective-C++ with Snow Leopard but they carry with them the worst aspect of Standard C: function pointer declaration and casting syntax. In this post, I'll show you how to understand declarations and casting syntax for blocks and function pointers, even in the worst of scenarios.

    Read article

  • Sep 28, 2009

    Objective-C era

    Optimizing the loading of a very large table on the iPhone

    In this post, I look at a UITableView on the iPhone which loads its data from a server and look at how its performance scales from single rows to tens of thousands of rows. I'll examine which aspects of the iPhone scale well and which become a burden as a displayed dataset moves from trivially sized to large sizes.

    Read article

  • Sep 22, 2009

    Objective-C era

    StreamToMe Version 1.1 available

    The latest version of StreamToMe — for streaming audio and video from your Mac to your iPhone/iPod Touch — is now available on the App Store. It has only been one month since I released version 1.0 but I have lots of new changes to share.

    Read article

  • Sep 21, 2009

    Objective-C era

    WhereIsMyMac, a Snow Leopard CoreLocation project

    In Snow Leopard, you can ask for the computer's location. Without a GPS, how accurate could that be? The answer in my case is: very accurate. In this post, I'll show you how to write a CoreLocation app for the Mac that shows the current location in Google Maps, so you can see exactly where your computer thinks it is.

    Read article