Cocoa
Introduction to Protocols
What follows is a quick introduction to working with protocols. This is good background information to understand as protocols are common in various Cocoa frameworks. A protocol is means to define a list of required and/or optional methods that a class implements. If a class adopts a protocol, it must implement all required methods in [...]
Basics of Notifications
What follows is a brief guide to working with Notifications in Cocoa. I’ll cover the basics, including registering an observer and posting notifications, just enough to start using notifications in your iPhone apps. There is an instance of NSNotificationCenter available to every running iPhone application. This class acts as an intermediary to facilitate communication between [...]
Single, Double and Triple Taps
If you need to tinker with the threshold (time between clicks) when working with single, double and triple taps on the touch screen, one approach for this follows. What follows is a short example that demonstrates how you can manage the delay between taps.
Get Application Name
If you ever need to get the name of your application in code, for example, to display the application name across a navigation bar, it’s as near as the bundle for your application. The code to get the name is as simple as this: [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; The breakdown is as follows:
NSNumber versus NSInteger
If you’ve ever found yourself scratching your head thinking “now which one should I be using, NSNumber or NSInteger?” the short summary below should help. NSInteger is nothing more than a synonym for a long integer. What follows is how NSInteger is defined:
Read and Write User Preferences
Reading and writing user preferences within iPhone applications is surprisingly easy given the NSUserDefaults class does most all the work for you. What follows is a short example to show how you can read/write two values, a boolean and an integer. The example assumes you want to save state as to whether a user wants [...]
Launching Your Own Application via a Custom URL Scheme
One of the coolest features of the iPhone SDK is an application’s ability to “bind” itself to a custom URL scheme and for that scheme to be used to launch itself from either a browser or from another application on the iPhone. Creating this kind of binding is so simple, its almost criminal not to [...]
Launching Other Apps within an iPhone Application (Part 2)
To continue on the types of URL Schemes that are supported by the iPhone (see Part 1); today I will show you how to: Launch YouTube “Deep Link” to content in iTunes
How to Mask an Image
Masking an image enables a developer to create images with irregular shapes dynamically. Masking is often used to create a user interface that is more compelling and less boring. Take for example the following example …
Date Formatter Examples – Take 3: Date from String
While working on an iPhone application recently, I needed to convert a date read from an XML stream that was in the following format: 20081122 to a nicely formatted string for display on the device: Saturday November 22, 2008.
“Default.png” the secret of the load screen …
Ever wondered how all of the applications on your iPhone seem to show a loading screen or “boilerplate” as soon as the icon is touched and wondered how they get the image to appear quickly? Well the secret is in the presence of a file in your application called Default.png.
Date Formatter Examples – Take 2: Format Strings
In the first post on working with dates several of the examples use the “old style” date format syntax. The examples work, however, I want to show an additional example that uses the ICU (International Components for Unicode) library for format strings.
How to “unfreeze” your iPhone Application
Have you ever found yourself stumped because your application locks up but doesn’t seem to crash or in any other way indicate that there is an error? If you have, then you are likely the victim of a common problem that can occur when you attempt to make certain changes to the UI outside of the main thread. Put more technically … you are doing something that is not “Thread Safe”.
Date Formatter Examples – Take 1: NSDateFormatter
Sometimes all you’re really looking for is a basic chunk of code to get something done. For example, I was working on an application yesterday and needed to display the current date in text format: October 29, 2008. A simple concept for sure, however, with the many nuances of date formatters, it takes some time [...]
How to Prevent iPhone from Sleeping
The automatic sleep timer is one of the ways the iPhone saves power. If the screen isn’t touched for a certain amount of time, it dims the screen and eventually turns it off. Although you should leave the timer on, there are times when this is not what you want (games are a good example). [...]








