Manually Adding a Swift Bridging Header

I watched the WWDC video, got excited, fired up my existing Objective-C project, added a Swift file, clicked “Yes” when Xcode helpfully offered to create a Bridging Header for me, and then watched helplessly as Xcode crashed. After crashing Xcode two or three times, I gave up, and added the bridging header myself, but how?

Here’s how:

1. Add a header file to your project, named [MyProjectName]-Bridging-Header.h. This will be the single header file where you import any Objective-C code you want your Swift code to have access to.

2. In your project build settings, find Swift Compiler – Code Generation, and next to Objective-C Bridging Header add the path to your bridging header file, from the project’s root folder. So it could by MyProject/MyProject-Bridging-Header.h or simply MyProject-Bridging-Header.h if the file lives in the project root folder.

You only need one Bridging Header. Add your #import statements to this file, and your classes will now be available in your Swift code without any extra import statements.


My First Day

I’ve had an on-again off-again relationship with blogging. I started with a generic “me” blog, then moved on to more focused topics. A Paris trip blog, a blog together with my wife about our baby, a very short lived gardening blog, and now that I’m going to be writing software again (this time full-time solo), I thought it was time to try once again. I’m not looking for an audience. Just a place to post some thoughts and to have an online home for my personal software career.

I’m getting back to coding after 3 years off, though I did start a project in 2008 which I worked on part-time for a few months. It is that project I will be picking up on in the next couple weeks. It’s called Turmeric (for now), and it’s a recipe/meal planning application for the Mac.

I just finished upgrading my computer to Snow Leopard, and I’m downloading the fat 2.5 GB iPhone SDK as I write this. I’ll be jumping into some Cocoa refresher tutorials and some iPhone tutorials on Tuesday.

Here I go!