Fri, Aug 9
C

Given space is often at a premium when writing applications for mobile devices, I want to show you how to use bitfields to manage a series of values that need only on/off status. The upside is that you can store a surprising number of status values within a single integer, 32 to be exact.

The code that follows is pure C. Given that Objective-C is a superset of C, don’t forget that you can leverage all that C has to offer, beyond working with objects.

Read more »

Wed, Jun 12
C

If you ever come upon a need to toggle an integer value between 1 and 0, consider using the bitwise exclusive-OR (^) operator in C to get the job done.

In a recent application I wrote a method with one parameter, an integer, that is expected to be 1 or 0. In creating a demo of the application I wanted to pass in alternating values of 1 and 0 as part of a test for a specific use case. Instead of using an if statement in the calling method to decide when to send a 1 or 0, I wrote something similar to the code below:
Read more »

Fri, Apr 26

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.
Read more »

Sun, Apr 14

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.
Read more »

Tue, Mar 5

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:

Read more »

Mon, Apr 6

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.
Read more »

Thu, Mar 26

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:
Read more »

Sun, Mar 1

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.
Read more »

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.
Read more »