Matt Gallagher: Cocoa with Love

Articles about Swift, Cocoa, software design and programming.

  • Jan 25, 2016

    Partial functions in Swift, Part 1: Avoidance

    Partial functions (functions with preconditions) are a risky design choice. You probably have a few in your program, even if you haven't clearly identified them. Learn how to recognize them, learn about their risks, learn to avoid them and learn why you might choose to use them anyway.

    fundamentalsmathematics

    Read article

  • Jan 25, 2016

    A new era for Cocoa with Love

    I'm drawing a line between the old Objective-C era posts on Cocoa with Love and the Swift era posts. The aim of the new era will be to make app programming suck less through a broad theme: "maintainable Cocoa apps". If we program with fewer runtime errors and new features are easier to add, we'll have more fun – even if "maintainable" sounds like a dull word.

    meta

    Read article

  • Jun 30, 2011

    Objective-C era

    A big weakness in Objective-C's weak typing

    We generally assume that we can send any message we want to a variable in our code typed as "id" and Objective-C's dynamic message handling will make the invocation work correctly at runtime. In some rare cases, this assumption is wrong. I'll look at situations where you need to be careful about sending messages to "id" typed variables and a situation where a limitation in the Objective-C language requires a hideous workaround to avoid serious bugs.

    Read article

  • Jun 19, 2011

    Objective-C era

    An RSS-feed and location-based iOS application

    The purpose of this post is so that I will have a link to give people when they ask: how do I write an iOS application that pulls data from an RSS feed, displays it pretty and can put things on a map. I'll show you all of that and more as I rewrite my oldest iOS application from scratch: FuelView.

    Read article

  • May 30, 2011

    Objective-C era

    Classes for fetching and parsing XML or JSON via HTTP

    In this post I show two reusable classes for fetching data via HTTP: one that parses the result as XML and another that parses as JSON. These are relatively simple tasks but due to the number of required steps, they can become tiresome if you don't have robust, reusable code for the task. These classes will work on iOS or on the Mac but the optional error alerts and password dialogs are only implemented for iOS.

    Read article

  • May 5, 2011

    Objective-C era

    Presenting a Mac dialog sheet with visual cue effects

    In this post, I'll show you how to use visual effects over a window to make a dialog sheet stand out when it is presented over the top. It's a pretty simple use of Core Image but is a useful technique to capture attention when needed.

    Read article

  • Apr 20, 2011

    Objective-C era

    Background audio through an iOS movie player

    Background audio in iOS is supposed to be as simple as entering a setting in your Info.plist and making sure your kAudioSessionProperty_AudioCategory is appropriate. This is true unless your audio is part of a movie file or is played in a movie player that has just played video — suddenly it becomes fiddly, hard to test, unreliable and changeable from version to version of iOS.

    Read article

  • Apr 5, 2011

    Objective-C era

    User interface strings in Cocoa

    In this post, I'll look at best practice for using and managing text strings in your user interface. This is a fairly simple topic but Cocoa has established "best practices" for handling user interface strings that new Cocoa developers should be aware of. Since it is inevitably related, I'll also look at the steps involved in localizing the strings in your applications but remember: you should follow good practice for string handling, even if you have no intention of ever translating your application.

    Read article

  • Mar 25, 2011

    Objective-C era

    Mac QuartzGL (2D drawing on the graphics card) performance

    QuartzGL was introduced as an official feature in Mac OS X 10.5 Leopard (although it was a developer-only feature in Mac OS X 10.4 as Quartz 2D Extreme). However, it is off by default and is largely ignored by most developers. In this post, I look at how to enable QuartzGL, the performance impact it has on different kinds of drawing and whether you should use it in your Mac programs.

    Read article

  • Mar 20, 2011

    Objective-C era

    A history of iOS media APIs (iPhone OS 2.0 to iOS 4.3)

    After initially starting with a small set of fairly basic media APIs in iPhone OS 2.0, the APIs and the features they provide have dramatically increased in the past 2 years and provided a rapidly moving target for developers trying to remain current. In this post, I'll try to summarize all of the different APIs in iOS 4.3 for playing media, when they arrived, what their purposes are, what their limitations are and what it's been like to remain up-to-date and support new features.

    Read article