Categories

AppKit

  • 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 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

  • Jan 31, 2011

    Objective-C era

    Advanced drawing using AppKit

    In this post, I'll look at drawing a detailed image in code by combining multiple visual elements. Unlike previous posts I've done on drawing in Cocoa, this will focus on the AppKit classes. The code will use NSGraphicsContext, NSBezierPath, NSAffineTransform, NSGradient, NSGlyph and show you some simple ways to export the contents of an NSView to a file.

    Read article

  • Nov 20, 2010

    Objective-C era

    Back to the Mac? 12 features from iOS I'd like to see in Lion

    A few user-features of Mac OS X Lion have been announced but no Cocoa API changes have been publicly announced. However, I think there are dozens of non-user areas where the Cocoa Mac APIs could be improved by integrating approaches from Cocoa Touch APIs. What follows are a dozen areas where I'd like to see a more iOS approach in Mac OS X Lion.

    Read article

  • Nov 12, 2010

    Objective-C era

    A Cocoa application for running scripts

    Last week, I showed a bash script that you can use to build, tag and package a Mac application. As I'll show you this time though, I prefer to use a compiled Mac application to do the same thing. The important code here is a set of classes that support script-like invocations of other programs and support for a structured build-log based on the results of each step.

    Read article

  • Sep 20, 2010

    Objective-C era

    Minimalist Cocoa programming

    In this post, I build and run a Cocoa Mac application on the command-line. This might not sound like a very difficult goal but I'll attempt to follow an additional constraint: use as few tools, components, classes and even lines of code as possible; truly minimalist Cocoa programming. The goal is to create an application that qualifies as a proper Mac application (including a menubar and a window) but without using Xcode, without an Info.plist file, without NIB files, without Interface Builder and without even using a text editor other than the Terminal itself.

    Read article

  • Jun 22, 2010

    Objective-C era

    The design of every Mac application

    I was recently asked by a reader if I used any modelling program to model the classes and relationships in my Mac applications. The answer is no, I don't model the application side of my programs. The reason for this is not because applications are always small and simple. The reason is that all applications have approximately the same design — eventually everything in a well-designed application becomes intuitive.

    Read article

  • May 17, 2010

    Objective-C era

    5 ways to draw a 2D shape with a hole in CoreGraphics

    In this post, I look at 5 different ways that you can draw a very simple shape: a square with a triangular hole cut out of the center. In a drawing environment like CoreGraphics which offers double buffering, winding count path filling, even-odd path filling and clipping regions, there's no single answer. An iPhone sample project is provided containing the code but all drawing functions are identical on the Mac.

    Read article

  • Apr 27, 2010

    Objective-C era

    Porting a Mac program to Windows using The Cocotron

    In this last of three posts about porting a Mac application to Windows, I look at the steps involved in setting up The Cocotron with a remote debugging session between Xcode and the application running on Windows. I'll also talk about the code that didn't "just work" and some of the approaches I used to fix the program and get it working.

    Read article

  • Apr 21, 2010

    Objective-C era

    Design of a multi-platform app using The Cocotron

    In this post, I'll talk about how multi-platform applications are structured and talk about some of the different ways that applications separate core logic from platform specific behaviors. I'll talk about how using a porting layer like The Cocotron fits into these designs and why using The Cocotron doesn't necessarily mean that you're ignoring best-practice or creating a second-class application.

    Read article

  • Apr 15, 2010

    Objective-C era

    Options for porting Objective-C/Cocoa apps to Windows

    There are a few different options for porting Objective-C/Cocoa applications to Windows. Each option has different advantages and offers different capabilities. In this post, I'll give an overview of some of these options, their advantages and disadvantages.

    Read article

  • Mar 29, 2010

    Objective-C era

    Streaming MP3/AAC audio again

    This week I present some further additions to AudioStreamer, a class I first presented in Streaming and playing an MP3 stream and revisited with bug fixes in Revisiting an old post: Streaming and playing an MP3 stream. This time, I'll add the two of the most requested features: seeking and HE-AAC audio support.

    Read article

  • Mar 15, 2010

    Objective-C era

    Custom UI Bindings in Interface Builder

    In my last post, I showed how you might redesign the interface to the iPhone's UITableView if you wanted to reimplement it on the Mac using Cocoa Bindings. This time, I'll show you how to make those bindings editable in Interface Builder so you can use the entire class with no code at all.

    Read article

  • Mar 10, 2010

    Objective-C era

    Designing a view with Bindings (UITableView on the Mac)

    Bindings are one of the best ways of connecting your view and model on the Mac but due to the layers of abstraction involved — and the fact that they don't exist on other platforms — bindings can seem foreign and confusing. In this post, I'll show a complex view that is traditionally implemented without bindings (the iPhone's UITableView) and show how it might be redesigned for the Mac with bindings.

    Read article

  • Dec 21, 2009

    Objective-C era

    A sample Mac application with complete unit tests

    In this post, I present a complete Cocoa Mac application implemented with unit tests for all created code. I'll create the tests first and then only add the code required to make the tests pass, largely following a test-driven development (TDD) methodology. Next week I'll show the configuration and implementation of this project as an iPhone application for the benefit of Cocoa Touch developers.

    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

  • Sep 16, 2009

    Objective-C era

    Building for earlier OS versions from Snow Leopard

    It is very easy, when developing on a new operating system, to create projects that won't run on any previous OS version. To ensure backwards compatibility, there are Xcode and gcc options that allow you to build while maintaining support for earlier OS versions. In this post, I'll look at the ways in which this compatibility is controlled and some of the new ways it can go wrong on Snow Leopard.

    Read article

  • Sep 9, 2009

    Objective-C era

    Creating alpha masks from text on the iPhone and Mac

    Alpha masks are a powerful way to create graphical effects in your program. In this post, I'll show you how to create an alpha mask from a text string and use that mask to create text-based effects with an image. I'll also show you how to do this on the iPhone and the Mac, so you can see the differences between these platforms in this area.

    Read article

  • Sep 1, 2009

    Objective-C era

    An NSSplitView delegate for priority based resizing

    The default resizing mechanism in NSSplitView is proportional resizing — if the NSSplitView changes size, each column resizes by an equal percent. This works badly in the common case where the columns in a split view are used to separate a side panels from a main view area (for example the "source list" in iTunes or the file tree in Xcode). In this post, I'll show you a delegate class that configures a split view for this side panel and main view behavior — resizing the views in a split view based on a priority list.

    Read article

  • Aug 14, 2009

    Objective-C era

    Animating a window to fullscreen on the Mac

    Many Mac OS X applications animate their regular application windows to fullscreen but since there's no dedicated method for the task, there's no standard Apple documentation that covers the operation. If you look for examples on the web, you'll find numerous examples that perform this operation using old APIs or methods intended for permanently fullscreen games (the wrong approach for an application window). In this post I'll show you my preferred approach for making an application window fullscreen, with continuous display and smooth animation.

    Read article

  • Aug 3, 2009

    Objective-C era

    Control and configuration of applications through Info.plist

    The Info.plist file is home to the metadata about your application used by the operating system. Most Cocoa programmers know that it stores the bundle identifier, icon name and version number of an application but the Info.plist can also control access to essential iPhone hardware resources and can change the very nature of your Mac OS X applications. In this post, I'll cover basic Info.plist usage and also explain some of the rarer settings.

    Read article

  • Jul 2, 2009

    Objective-C era

    Custom views in Interface Builder using IBPlugins

    If you have custom views configured in code, it can be time consuming to configure them for each instance and make them look right in context. To make the process smoother, you can create Interface Builder plugins and configure your objects in Interface Builder. While the Xcode documentation explains how to do this, it is long, thorough and confusing. Here is the simplified set of steps that I use to create Interface Builder plugins quickly.

    Read article

  • Jun 17, 2009

    Objective-C era

    Revisiting an old post: Streaming and playing an MP3 stream

    Given the attention it received and the number of bugs I know it contained, I wanted to revisit an old post of mine: Streaming and playing an MP3 stream. In this post, I'll talk about the problems the original contained, how I fixed those problems and I'll present the updated result.

    Read article

  • May 4, 2009

    Objective-C era

    Invoking other processes in Cocoa

    Invoking other processes is a good way to handle some low-level tasks on the Mac. I'll show you some simple ways to invoke processes and parse their outputs in Cocoa apps as well as some advanced tricks like running a process with administrator privileges.

    Read article

  • Jan 18, 2009

    Objective-C era

    Demystifying NSApplication by recreating it

    In this post I will recreate code that is normally concealed between the NSApplicationMain call (invoked in a Cocoa application's main function) and the sendEvent: method (which distributes the events to windows and views from the main run loop). By recreating this code for you, I hope to explain the steps that occur between program startup and the dispatch of events to your code — so you can gain greater understanding of what NSApplication does on your behalf.

    Read article

  • Dec 12, 2008

    Objective-C era

    Drawing a custom window on Mac OS X

    Occasionally, you may want a window to look completely different to the standard window styles provided by Apple. This post will show you how to draw a custom window and implement close, resize and drag functionality.

    Read article

  • Nov 16, 2008

    Objective-C era

    Singletons, AppDelegates and top-level data.

    If you require only a single instance of an object in your application, where should it go? How should you control and manage it? Here are some different approaches, their implementations, their strengths and their weaknesses.

    Read article

  • Oct 10, 2008

    Objective-C era

    WorldTimeConverter: Dates and timezones in Cocoa

    Recently, I searched for a world time converter — one that would handle future dates as well as the current time. There are web versions but I didn't find a genuine Mac OS X application that matched my desires. How hard could it be? The answer is 1 subtraction — provided you can find the right values to subtract. Read on and I'll show you how it's done.

    Read article

  • Sep 9, 2008

    Objective-C era

    Parametric acceleration curves in Core Animation

    CAMediaTimerFunction is used to control basic acceleration along a path in Core Animation but is very limited in what in can do. In this post, I look at the mathematics behind CAMediaTimerFunction and present a sample application that simulates some functions that CAMediaTimerFunction can't achieve by using parametric CAKeyframeAnimation values.

    Read article

  • Aug 31, 2008

    Objective-C era

    Application Design in AppKit

    This is a discussion of high-level application design in Cocoa that aims to explain the major class roles in an AppKit application and how they are connected. I'll show you much more detail than simply "Model-View-Controller" and I also give a specific example of how all the concepts apply to a real application.

    Read article

  • Jul 21, 2008

    Objective-C era

    Better integration for NSViewController and NSView

    NSViewController simplifies loading an NSView from a NIB file. But it has some limitations compared to NSWindowController (its window loading/managing equivalent). In this post, I'll explain the limitations and present options for overcoming them.

    Read article

  • Apr 20, 2008

    Objective-C era

    viewWillDraw - a welcome addition to NSView in 10.5

    A method named viewWillDraw appeared in NSView in Mac OS X 10.5. If you have cause to use it, this method replaces 6 other methods from earlier versions of Mac OS X. Read more to find out if you should use it and how it helps.

    Read article

  • Mar 14, 2008

    Objective-C era

    Cocoa Application Startup

    How does a Cocoa Application start up? Where are the main places to put code so that it gets run on startup? Learn the answers in this series of startup diagrams.

    Read article