$aleOrigin

Cocoa

Please consider subscribing to Mobile Developer Tips
RSS feed or following us on Twitter


NSRange and NSString Objects

When poking around NSString methods you’ll find many references to NSRange, which is nothing more than a C structure that is helpful for describing a series of items, including a starting location and a count. For example, a range is helpful to extract a substring from another string, where you specify the starting location and [...]

Cocoa

Compare NSString Objects (Updated)

This tip is for those new to Objective-C and Cocoa and walks through some basics on comparing NSString objects for equality. Compare NSString objects with == NSString *str1 = @"Homebrew"; NSString *str2 = @"Homebrew";   // This compares the addresses of the string if (str1 == str2) NSLog (@"str1 equals str2"); else NSLog (@"str1 does [...]

Cocoa

Download, Create and Display an Image from URL

This tip will show the steps to download and display an image from a remote resource. This is handy if you need to add an image as a subview, yet, the image is not part of your application bundle. URL to Remote Image We start by creating a URL to the remote resource: NSURL *url [...]

Cocoa

Date Formatter Examples – Take 4: Setting Locale

A reader recently wrote and asked how to show a date output in a different language. By default, the NSDateFormatter will use the locale set on the device, so no code specific locale changes are required if you want your app to display in the current locale. However, if you need to display a date [...]

Cocoa, Date and Time

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 green:g/255.0 blue:b/255.0 alpha:a] Here’s the code without/with the [...]

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
All Content Copyright © 2008-2012 • Mobile Developer Tips, All Rights Reserved.
iPhone and iPad are registered trademarks of Apple, Inc.
iOS is a registered trademark of Cisco Technology, Inc.