Apple’s overly aggressive deprecation sucks.
If you are still maintaining a Carbon application for Mac OS X, you may have stumbled upon a serious issue with handling of nib (interface) files in Xcode 4 under Lion, and if you have not yet, you probably will soon. Hopefully, this post will help you resolve problems or avoid some of the pitfalls.
Apple marches forward and aggressively deprecates development technology. In this particular case, they release Xcode 4 and only allow submissions to the Mac App Store from the latest version, forcing developers to upgrade. We are maintaining and enhancing a product that was developed using Carbon, based on Apple’s (then) recommendation for cross-platform products, and was about 90% complete when they announced its deprecation in favor of Cocoa.
Additionally, we upgraded to Lion (to properly provide customer support), unaware that the latest version of Xcode 3, version 3.2.6, would not install or run on Lion. Instead, we could only download and install Xcode 4.1, which does not provide support for Carbon nib files. With Snow Leopard, we could download both versions normally, but from Lion, the Xcode 3 download link is removed and Xcode 4 is only available via the Mac App Store. More accurately, the installer is available via the Mac App Store; you still need to find it in Launchpad and run it before Xcode is ready.
There are two particular problems that occur with Carbon nibs in Xcode 4.1:
First, there is no editing capability for modifying them, so when you highlight a Carbon nib, the editing window only displays an Interface Builder icon, but (importantly and annoyingly) there is no message that editing is not supported. Unless you already know that is the case, you will waste some amount of time attempting to figure out how to activate the “integrated” Interface Builder.
Second, the build tools provided cannot process the older nib files, so you will get a message similar to the following: ‘error: ibtool could not strip “Main.nib” because it is not a valid Interface Builder document.‘
Of course, there are a few obvious options here. If you stop upgrading your development system, you can still build on Xcode 3.2.6 under Snow Leopard, except that you cannot submit to the Mac App Store. You may be able to have both versions in parallel, but that is not an option on Lion at all, and the nib build issue still exists in Xcode 4 (although the solution to that is provided below). Finally, you can give in to Apple’s strongarm tactics and rewrite your application to use Cocoa, but that is not always feasible, economically or otherwise. (In our case, we are trying to maintain our products and support our customers while we rewrite it with Cocoa.)
Or, I suppose, you could flip Apple the bird and abandon their Mac platform; that has crossed my mind more than once, but it is not really an option for us. Instead, I found a way to resolve the two main problems above, without too much effort. (That is, it will be fairly easy for you readers; it took me significant time to figure this all out.)
To resolve the inability to edit Carbon nib files within Xcode 4, take advantage of the fact that Interface Builder was an external tool with Xcode 3, and that it does run in Lion. Simply copy Interface Builder 3.2.6 from a (Snow Leopard) partition on which it is installed to the Lion partition. It should be located (by default) in the ‘/Developer/Applications’ folder, and note that it must be copied to the same directory on the Lion partition after Xcode 4.1 is installed. (It will not run properly from a different folder, and the Xcode installer apparently removes it [so make a backup copy].) Since Xcode will no longer launch (the external) Interface Builder automatically, you will probably want to make an alias for it in a convenient location.
Then, to resolve the build problems with the older nib files, you must use the separate Interface Builder tool to covert your nib files to a newer (XIB) format. This is accomplished by opening each nib file in IB, selecting ‘File->Save As…’ from the menu, changing the ‘File Type’ to “Interface Build Carbon Document (XIB 3.x)”, and saving. You will then need to open your project in Xcode, add all of the new .xib files to it, and delete the older .nib files. Clicking on one of the .xib files in Xcode will show/edit it as an XML file (instead of just an icon) but, of course, you will probably only want to edit it in your newly installed IB3.
There may (read: probably will) be other issues, both with Xcode 4 itself and with the newer SDKs. For example, we use one (and only 1) function defined in ‘QuickdrawAPI.h’, which has been removed from the OS X 10.7 SDK, so we had to back down to the 10.6 SDK (plus each SDK has different versions of the zlib library available). Also, several of our windows from (converted) nib files produce a new warning: “This window’s content rectangle does not lie entirely on the screen with the menu bar and may not be completely visible for all screen resolutions and configurations.” (We dynamically adjust most of our windows anyway, so it appears to make no difference, but we have yet to eliminate these warnings.)
Nevertheless, making the above changes will allow an older Carbon-based application to be built on Lion using Xcode 4.1, leaving you free to discover more fun and excitement.
[If you find this information useful, please leave a meaningful comment.]