Our DNA is written in Objective-C

The Amazing Responder Chain

Do you remember, back when you first opened Interface Builder?

How long did it take you to understand the purpose of File’s Owner?

That is a proxy for the object that loads this NIB, usually a UIViewController. This allows you to connect IBOutlets and IBActions with elements contained in the NIB file. IB knows about these because you tell it what class the File’s Owner has and from parsing this class’ header it finds all things that you can connect to by the IBOutlet and IBAction keyword.

That one was easy. Second question: How long did it take you to understand the purpose of First Responder?

If you are like me then you started out developing for the iPhone and other iOS devices. And then you probably also learned to ignore this proxy object because on iOS it does not serve an obvious purpose. In fact you can go for years developing iOS apps without ever doing anything with it. I know I did.

It is only know that I am starting to dabble in developing for the Mac that I had to begin to develop and appreciation for the responder chain. And so finally I understand the purpose and usefulness of the “First Responder” object and I want to share this with you.

Read more

BSA Banner

Fun with UTI

… no, were not talking about the kind of fun that burns when taking a leak. In this article I want to summarize what I learned over the past weeks about working with Universal Type Identifiers.

On Windows files where always only identified by their file extension. In the olden days Apple was using multiple additional methods of determining what to do with certain files, amongst them HFS codes and MIME types.

The modern way to deal with file types is to use UTIs which are typically a reverse domain name, like “public.html” for a generic HTML file or “com.adobe.pdf” by the PDF type created by Adobe. UTIs have an additional advantage that other methods of identifying types do not possess: a file can actually possess multiple types.

Read more

Radar: CGRectMakeWithDictionaryRepresentation

This is one of those rare jewels of a bug that will cost you days to figure out if you encounter it in the context of a large app. It makes you doubt our own sanity until you come to the painful conclusion that the problem indeed resides in Apple’s code, not yours.

In this special case we had a couple of rare circumstances that worked together to form a scenario where CGRectMakeWithDictionaryRepresentation partially fails to reconstitute a CGRect from a dictionary. This function is literally ancient, it exists since iOS 2 and Mac OS 10.5. This makes it even more implausible that nobody has stumbled across this before us.

In the project where we first saw the problem these where the steps that led to this bug’s discovery:

  1. Create a CGRect that is not an integer
  2. Write a dictionary from iOS simulator which contains a dictionary encoding this CGRect
  3. Open this dictionary in Xcode’s property list editor
  4. Upon saving some of the least significant digits change in the “real” items
  5. This new dictionary can no longer be parsed on iOS

What’s even funnier is that some such modified values can still be read, but then the function fails internally and the remaining values don’t get parsed, i.e. stay zero.

From what I have seen researching this bug looks like certain floating point numbers cannot be represented on iOS. The normal parsing functions are able to round to the closest value that can be represented in 32-bit floats, whereas CGRectMakeWithDictionaryRepresentation fails to do so. The first value that cannot be exactly represented is truncated, all following values turn out to be Zero.

This was filed as rdar://12358120 and on OpenRadar.

Read more

Component Shuffling

I made some updates recently that I wanted to mention so as to minimize some surprises. Also there are some  changes that were prompted by iOS 6 being released.

Read more

Target Conditionals and Availability

The great thing about building apps for both iOS and Mac is that many pieces of code work just the same on both platforms. There are some scenarios however where you want to add different kinds of Apple SDKs based on which platform you are building for.

A good place to put all headers that often used is the Precompiled Header File (PCH) which gets precompiled and then reused throughout your app. Whenever you have an #import statement in your code the compiler needs to figure out whether this header has already been imported because the same header file can potentially be imported from several locations.

I generally like to put all imports for Apple headers into my PCH file as well as my own app-wide classes like my DTFoundation library which has a growing selection of methods that I frequently use. Having these imports in the PCH means that the preprocessor can prepare them for faster compiling once and then can virtually prepend all these definitions for every source code file.

Today I learned something new, namely how you can use the same PCH for Mac as well as iOS.

Read more

OS X Tutorial for iOS Developers (2)

In the first part of this series we started out by setting up the document type and export the UTI for the system to know about it. We also implemented methods to read the index from a file wrapper as well as persisting it to a new one. These steps where sufficient that we ended up with all the file manipulation candy (reverting to earlier versions, new doc, etc.) functional.

I promised that we would get go something more interesting today. We’ll be wiring up an NSCollectionView to show thumbnails and names of our images contained in shoebox documents. Then we need to dive into pasteboard as well drag-and-drop functionality to be able to manipulate those shoebox images. We want to be able to drag images from Desktop into shoeboxes and – time permitting – also be able to change their order by dragging as well.

Please let me know if this kind of tutorial is of interest to you by using the Flattr button and/or sharing it in your favorite social network.

Read more

iOS 6 out now

True to the predictions iOS 6 became available worldwide at exactly 7 pm central European time. The nice guys at istheapplestoredown.de were the first to call it and send out the notification e-mail that you can subscribe to.

The first question foremost on every developer’s mind: is the released version the same as the Gold Master.

Read more

Back on Mac – OS X Tutorial for iOS Developers

I’ve been programming for the iOS platform ever since this is possible, since the iPhone 3G with iPhone OS 2.0 was released by Apple in Summer 2008. For all this time I had a healthy respect about programming for Mac. More precisely: Horror.

If you dig into it you can only applaud Apple for not having tried to craft touch screen and energy optimization stuff onto AppKit, but chose to go the forked OS route. Being a seasoned iOS developer you will find yourself often cursing about how complicated certain activities seem.

Having said that you also see the positive influence of iOS on AppKit all around. Now that Apple deprecated Garbage Collection and you are already well used to programming under the ARC paradigm you find yourself writing exactly the same code for both platforms more often than not.

This will be the first in a series of tutorials where I am sharing my experiences in diving into AppKit. Please let me know if this is in fact interesting to you by sharing and Flattr’ing it.

Read more

Retina Iconset Trouble

When I was done with QA on Linguan 1.1.2 I wanted to submit it for review. But when I tried the validation step in Xcode halted me. It complained that I didn’t have a 512×512@2x icon. Then it dawned on me: Retina Macs.

So you have to imagine me, all excited about being able to submit this, but unable to do so. The icons for Linguan were all contained in an icns and I was stumped … but only for a moment. With help from David Smith I was able to prepare an iconset, the best current method for preparing the multiple resolutions of icons for Mac apps.

Read more

iPhone 5 Keynote Event

We just witnessed the iPhone 5 launch …almost live … at the Runtastic HQ where there was a Cocoahead special event. Let’s summarize what it means for us developers.

Tim Cook called iOS 6 and iPhone 5 the “biggest thing to happen to the iPhone since iCloud”.

Read more