PacktLib: Cocoa and Objective-C Cookbook

Cocoa and Objective-C Cookbook


About the Author

About the Reviewers


User Interface Components


Using a NSTableView

Using a NSOutlineView

Using NSSplitView

Using the WebView

Displaying a NSAlert

Formatting dates

Formatting numbers

Importing images

Saving preferences with NSUserDefaults

Retrieving preferences with NSUserDefaults

Adding a password to KeyChain

Retrieving a password from KeyChain

Accessing the Address Book

Adding an event to iCal

Custom Views


Drawing in your custom view

Using your custom view in Interface Builder

Handling mouse events in your view

Handling keyboard events in your view

Drawing strings with attributes

Handling Events


Interpreting the pinch gesture

Interpreting the swipe gesture

Interpreting the rotate gesture

Handling special keys

Working with NSResponder

Application-wide notifications with NotificationCenter

Using Animation


Understanding the CALayer class

Animation by changing properties

Using animation to swap views

Using the flip animation

Using a CAAnimationGroup

Using Keyframe animations

Using CAMediaTiming in animations

Objective-C 2.0


Using blocks

Switching compilers

Create your own framework

Using garbage collection

Fast enumeration

Declared properties

Application Architecture


The Singleton design pattern

The Factory design pattern

Using delegation in your own classes

Using an NSTimer for periodic events

Working with Key-Value Coding

Using operators with Key Value Paths

Using NSAutoreleasePool

Better Debugging


Using special environment variables

Using Instruments for performance

Handling exceptions

Knowing when you are being debugged

Using Debugger() and DebugStr()

Using Build and Analyze in Xcode

System Integration


Adding a Badge to your Dock icon

Adding a Menu to your Dock icon

Creating a disk image for your application

Updating your application With Sparkle

Working with Files


Saving your class with NSKeyedArchiver

Loading your class with NSKeyedUnarchiver

Finding special folders

Basic XML parsing

Parsing JSON

Working with the Web


Using NSURLConnection with HTTP GET

Using NSURLConnection with HTTP POST

Adding a hex encoding category to NSData

Adding a hex decoding category to NSString

Adding a Base64 encoding category to NSData

Adding a Base64 decoding category to NSString

Adding a MD5 hash category to NSData

Escaping a URL

Working with Databases


Inserting a row with MySQL

Using prepared statements with MySQL

Selecting data using MySQL

Inserting a row with SQLite

Using prepared statements with SQLite

Selecting rows using SQLite



Playing movies with QuickTime

Playing an audio file

Using a Core Image filter

Getting EXIF information from an image