Search This Blog

Tuesday, January 24, 2012

XCode 4.2 and a "From Scratch" Chameleon Build

Link Below...
I have been using "Xcode 4.2 for Lion in the Mac App Store" version 4.2 (the latest version is 4.2.1 which I doubt will make much difference here but I have not tried it  apparently 4.2.1 in the app store is 4.2 in XCode "About"??).

I am working on a project involving MIDI that will run on Mac OS X and iOS devices (as well, some day, on Windows).  My goal is to create a common UI between both Apple systems using "Chameleon."

Chameleon is a "white room" implementation of the UIKit interface on iOS devices (details on the site).

I downloaded Chameleon as a .ZIP and was able to get things to work under XCode 4.2 by simply following the instructions.  However, if I intend to use this in my applications I need to make sure that this will work from scratch.

(You might ask "why not just use the supplied Chameleon project as a base?"  I will never do that because of my past experience.  Often I have found that you get to a point in XCode development projects where the project is broken in some way relative to what you need to do to solve some issue and you want to start over because that's the fastest way.  If the supplied Chameleon project has a problem like this I am, as they say, hosed.

In addition things like XCode 4 - which seem to me ill thought out like Lion - change basic paradigms and there is not easy direct route between say XCode 3.2.6 and where you want to be.)

On the iOS side this was pretty straight forward.  Basically by creating an empty "View" iOS project and installing re-written (new file and class names) versions of each of the Chameleon files.

The result worked as advertised.

However, on the Mac OS X side things were somewhat trickier.  Below are the things I found that made this hard:

First, you need to create new project and be sure to include the "Document-Based" option:


The resulting project will have only a "Document.h" and a "Document.m" source file.  You need to do this because you will need the "Document.xib" file that is also created.

Second, in XCode 4.2 its important to use the Document.h/m files because they are tied to the .xib file.  I fooled around for some hours trying to do this from scratch in a non-Document project without any useful results.

(I redid each of the files with new names and class names just to ensure that I wouldn't have other problems on the OS X side.)

This means you need to merge the MyDocument.h/m contents into the XCode-created Document.h/m files (replace the contents of Document.h/m with the guts of MyDocument.h/m supplied with Chameleon).

Third, you must change the name returned inside windowNibName to "Document" as well.

Fourth, I also had to edit the #import <UIKit/UIKit.h> imports to #import "UIKit.h" and include the locations of the "Classes" folder in the supplied Chameleon UIKit sub-project.   Without this XCode cannot resolve the #import.

Fifth, I also put the .XIB files into Resources sub-folders.

Six, you need to add the Chameleon UIKit project to your project and then open "Targets>Build Phases>Link With Binary Libraries."  Click the plus (+) and select "UIKit.framework".  Be careful here because removing things and adding them back, like the UIKit project seemed to cause problems.

Finally, I rebuilt all the Toolbar and main window in InterfaceBuilder.  I manually checked to make sure everything linked together between the various IB elements and my classes.

The result worked just as the distribution did.

Now I am moving on to install my iOS code into Chameleon to see how well it works.

All told this was far less work than re-writing my code or creating the equivalent to Chameleon.

(Relative to XCode 3.2.6 - creating empty projects behaves differently than XCode 4.  Basically they do two completely different things and importing the older version to me is just asking for trouble.

A lot of XCode 4 to me seems like it involves doing things "just so" - and if you don't know what that is you are lost (see this as an example).  XCode 3.2.6 was quirky but usable because it did much less "magically" for you.

IB is also an issue here - it seems like each release works slightly differently than the last - and mostly in ways that involve an hour of Googling to find that one thing that's missing.)

No comments:

Post a Comment