Cocoa

iPhone SDK 3 and Deprecated Method Warnings

A side-effect of developing code on platforms that continue to evolve, is dealing with methods that become deprecated from one release to another. If you’ve spent anytime at all with Java, you are all too familiar with this concept. With the release of the iPhone SDK version 3.0, a number of methods have been become [...]

Cocoa

UIColor Macros

Below are two macros I paste inside every new iPhone project. Besides saving a few keystrokes, they work well when using the color picker application. Let’s look at the macros first:

#define RGB(r, g, b)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a)
[UIColor colorWithRed:r/255.0 [...]

Cocoa

Changing Views to Landscape Mode

As you well know, by default, iPhone applications launch in portrait mode. If you need to start your application in landscape mode, you can set UIInterfaceOrientation key in the plist file. The two possible values for this key are: UIInterfaceOrientationLandscapeLeft (iPhone home button will be on the left) and UIInterfaceOrientationLandscapeRight (home button on right).

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 [...]

Cocoa

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 [...]

Cocoa

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.

Cocoa

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:

Cocoa