Apr 26 2009

Introduction to Protocols

Published by john under Cocoa

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 the protocols it adopts.

Cocoa uses protocols to support interprocess communication through Objective-C messages. In addition, since Objective-C does not support multiple inheritance, you can achieve similar functionality with protocols, as a class can adopt more than one protocol.
Continue reading...

No responses yet

Apr 14 2009

Basics of Notifications

Published by john under Cocoa

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 apps.

There is an instance of NSNotificationCenter available to every running application. This class acts as an intermediary to facilitate communication between objects that are interested in being notified at some point in the future (these objects are known as the observers) and a poster that posts to the notification center, resulting in all observers (registered for a specific notification) being called.
Continue reading...

2 responses so far

Apr 06 2009

Gotcha: GCC and Unused Values

Published by john under Xcode

Subtle typos and the problems they bring, it’s enough to drive one nuts. Let me share a recent experience that will shed some light on my most recent experience. Below is a short snippet of code that show something similar to what I was recently attempting to do. It’s nothing more than a variable definition, and in one place incrementing the variable, in another I decrementing.
Continue reading...

3 responses so far

Mar 26 2009

Xcode Code Completion Macros

Published by john under Xcode

In the previous post I described the basics for working with code completion in Xcode. In this post I will show how you can use built-in text macros to insert various code fragments.

As an example, begin by entering ifelse into Xcode and follow this by pressing Control . (control period) and you’ll see the following code block inserted:
Continue reading...

No responses yet

Mar 05 2009

Xcode Code Completion

Published by john under Xcode

What follows is a quick review of how I use code completion in Xcode. Chances are that options and features exist beyond what I’ll cover here, so comments and suggestions are welcome.

Let’s say I want to insert a CGRectMake method. I can begin by typing CG and pressing F5 (or Option-esc), which will popup a list of possible matches:
Continue reading...

7 responses so far

Mar 01 2009

Safari 4 Beta

Published by john under General

A little off topic, but a good tip none the less…

Apple recently released Safari 4 beta and if you haven’t given it a try, I highly recommend you do.
Continue reading...

Technorati Tags:

No responses yet

Mar 01 2009

Objective-C Object as a C Structure

Published by john under Objective-C

Okay, so figuring out how to unwind an Objective-C object into its base representation goes against all that is object-oriented programming, however, it’s interesting none-the-less.

In Objective-C there is a directive, @defs(), that outputs (at compile time) the list of instance variables for a class. We can use this list to create a C structure with the variables of a specified class.
Continue reading...

2 responses so far

Next »