Oct 28, 2013

Apple breaths new life into AppleScript on Mavericks

Don Southard on AppleScript and Mavericks:

Once I started to sink my teeth into some of the power-user features, though, it didn’t take long for me to really get sucked into trying out every new geeky addition, specifically all of the new AppleScript features.

In a surprising turn of events, Apple decided to breath new life into AppleScript and make it easier than ever to write clean and reusable scripts.

Cocoa turns 19 years old, a little history

Graham Lee on the history of Cocoa:

First there came message-passing object oriented programming, in the form of Smalltalk. Well, not first, I mean first there was Simula 67, and there were even things before that but every story has to start somewhere. In 1983 Brad Cox added Smalltalk messaging to the C language to create the Object-Oriented pre-compiler. In his work with Tom Love at Productivity Products International, this eventually became Objective-C.

Graham goes on to provide information on a series of books, all leading to what we now know as Cocoa.

Happy Birthday Cocoa.

Aug 9, 2013

Bitfields in 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.

Continue reading...

Jun 12, 2013

Using XOR to Toggle an Integer Between 1 and 0

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:
Continue reading...

Apr 26, 2013

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

Apr 14, 2013

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

Mar 5, 2013

Xcode Code Completion

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

Apr 6, 2009

Gotcha: GCC and Unused Values

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

Mar 26, 2009

Xcode Code Completion Macros

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

Mar 1, 2009

Safari 4 Beta

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

Objective-C Object as a C Structure

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

Feb 23, 2009

Open Source Screen Capture Tool

I’ve been on the hunt for an open source screen cature tool for the Mac. I finally found what I was looking for, a tool that in which you can specify the exact size of the capture window. Let me explain…

In the process of creating screenshots to accompany applications submitted to the App Store, you can include up to 5 images. Although the images can be anything you like, typically the images consist of screenshots of an application running in the iPhone simulator. When working with the simulator there are two sizes used most frequently, 320w x 460h (Apple recommends not to show the status bar across the top) and 480w x 320h (landscape mode).
Continue reading...

Feb 19, 2009

Xcode Expert Preference Settings

Beyond the settings you can access from the Preferences menu of Xcode, there are a number of configurable options that can be set using the defaults command from a terminal window.

Two of the settings that I have configured are to beep when a left bracket ( ] ) is entered without a matching right bracket, and second, to increase the number of entries in the recent projects menu (File menu, Recent Projects).
Continue reading...

Feb 1, 2009

Change Company Name in Xcode

Although covered many other places on the net, I recently had to make a change to the name that Xcode automagically inserts when creating new files, so I figured I’d also pass on this tip to readers of this blog as well.

By default, Xcode inserts a company name something similar to the following in all new source files (.m .h etc):
Continue reading...

Jan 16, 2009

Date Formatters – Part 3

While working on an iPhone application recently, I needed to convert a date read from an XML stream that was in the following format: 20081122 to a nicely formatted string for display on the device: Saturday November 22, 2008.
Continue reading...

Jan 9, 2009

Date Formatters – Part 2

In the first post on working with dates several of the examples use the “old style” date format syntax. The examples work, however, I want to show an additional example that uses the ICU (International Components for Unicode) library for format strings.
Continue reading...

Dec 30, 2008

Date Formatters – Part 1

Sometimes all you’re really looking for is a basic chunk of code to get something done. For example, I was working on an application yesterday and needed to display the current date in text format: October 29, 2008. A simple concept for sure, however, with the many nuances of date formatters, it takes some time to pull together the “right” code.
Continue reading...

Dec 23, 2008

Xcode FIXME and TODO

In a previous post I introduced how to use #pragma mark to help navigate source files within Xcode. There are several additional tags that can be used within a source file to call out specific code or content.
Continue reading...