TweetFollow Us on Twitter

Xcode Rising

Volume Number: 19 (2003)
Issue Number: 8
Column Tag: Programming

Getting Started

Xcode Rising

by Dave Mark

Beautiful weather. A gorgeous new venue called Moscone West. And a keynote by Steve Jobs. Ah, the annual pilgrimage to Apple's World Wide Developers Conference. I had a great time and met a lot of you at the conference. Moscone West is across 4th street from Moscone Center, the traditional site of MacWorld Expo. A state of the art facility, WWDC marked its maiden voyage. Yes, we were the first conference ever held here. Cool!

As usual, Steve Jobs did an excellent job with the keynote (check out Scott Knaster's July column for a blow-by-blow account). My favorite part was when Steve rolled out Xcode, Apple's replacement for Project Builder. Everyone who attended the conference got a set of Xcode disks, one install for Panther and another for Jaguar. Since Panther is still not released, I thought I'd focus on the Jaguar version of Xcode.

Xcode In, Project Builder Out

To start off our guided tour of Xcode, let's take a classic Project Builder project and open it in Xcode. First, launch the Xcode app. You'll find it in /Developer/Applications. Once Xcode launches, select Open from the File menu. Navigate into the Sample Code directory in /Developer/Examples/AppKit/. We'll be playing with the Sketch project. In Xcode's open dialog, you could click on the Sketch directory, then scroll through all the files looking for the project file. But do this instead: Click on the Sketch directory, then click the Open button without selecting a file to open. Xcode will find and open the first project file it encounters in that directory. Cool!

    Yeah, I know, why not just find the project file in the Finder and double-click it? Two reasons. First, I wanted to show off Xcode's ability to auto-open the project file. And second, I still have Project Builder installed on my machine. Since Sketch's project is a Project Builder file, when I double-click on the project, the Finder launches Project Builder.

    Another solution: In the Finder, click on the project file, then do a Command-i to bring up the Get Info window (see Figure 1). Click on the Open with: disclosure triangle and select Xcode from the popup menu. If you have not yet run Xcode, select Other... from the popup and go find the Xcode app. You can click on the Change All... button to make this change for all your Project Builder projects.


Figure 1. Contents of ARTIS Screen Tools 2.5.3.

When you click the Open button, Xcode will warn you that you are opening an old project file and that it will be upgraded if you continue (See Figure 2). Not a prob. Click the Open button and let's charge forward.


Figure 2. Warning! You are opening an old project file. It will be assimilated.

Figure 3 shows the Sketch project window that appears once Xcode upgrades the old Project Builder project file. If your project window looks radically different, perhaps you've mucked with the preferences or customized the toolbar (the strip of icons at the top of the window). To get back the original toolbar, select Customize Toolbar... from the View menu, drag the default toolbar from the bottom of the window that appears to the toolbar at the top of the window, then click Done. Definitely worth spending a minute or two with this, just to get a sense of the kinds of changes you can make to your toolbar.


Figure 3. The Sketch project window.

A Whole New Build System

When Xcode upgrades an existing project file, it converts the project file format, but does not convert the targets themselves. To understand what this means, you have to know a little bit about build systems. Project Builder originally used Make as its build system. Make is a traditional Unix utility that parses dependencies listed in a text-based makefile.

    If Make is new to you, take a minute, fire up Terminal, and type in the command man make. This will list the man pages for the make command and will give you the basics on build systems.

Over time, Project Builder moved to an open source build system named Jam. Here's a link that'll give you the basics on Jam:

http://www.perforce.com/jam/jam.html

Jam offers a more compact and sophisticated build language than Make, but is still a text-based build system.

Xcode uses its own, native build system, a build system that is more tightly integrated with the IDE, has a better understanding of the project dependencies and, therefore, produces better build performance. Since the command line and graphical versions of the build system were themselves built from the same frameworks, there is no noticeable performance change when you move between the two.

    You can still use the legacy build mechanisms that work with Project Builder. However, you'll need to move to "native builds" if you want to take advantage of Xcode features like Zero Link, Fix and Continue, and Distributed Builds.

Upgrading the Sketch Target

Our next step is to upgrade the Sketch target so it uses Xcode's native build system. In the project window's Groups & Files pane, click on the Targets disclosure triangle to reveal the list of targets in this project. At this point, there is a single target, named Sketch. Click on Sketch, then select Upgrade Target to Native from the Project menu.

A panel will appear in the project window that tells you what is about to happen and gives you a chance to name your new target (Figure 4). Leave the name as Sketch (Upgraded) and click the Upgrade button.


Figure 4. Naming your new, native target.

Now, when you look at the list of targets in the project window, you'll see your new Sketch (Upgraded) target. Select Sketch (Upgraded) from the popup in the upper-left corner of the project window to make this target the active target (Figure 5). Note that the active target has a small green checkmark in its icon.

Active targets are important! When you do a run, build, or debug, the active target is the one that is run, built, or debugged. You might have one target with full debug info turned on, and a second target that is optimized with no debug info. You might have one target that uses a legacy build system and another that uses Xcode's native build system. Make sure you have the right active target selected before you do your build.


Figure 5. Make the new, Sketch (Upgraded) target the active target.

Xcode uses the inspector window to modify target settings. As an example, select the Sketch (Uprade) entry under Targets, then bring up the inspector window (either click on the i-in-a-circle on the toolbar, or type command-i). In the inspector window, click on the Build tab. Each entry in this list is a setting followed by a value. Some values are set via popup menus, some by typing in text, others with checkmarks. Depends on the setting type.

Take a careful look at Figure 6. There's a lot going on here. First, I clicked on the Build tab, then clicked on the little "drawer" icon in the lower left corner of the inspector window. This opened the drawer to the side, which allows me to select from different sets of settings.

I then clicked on the Prebinding setting to select it, then clicked on the split bar at the bottom of the window and dragged it up, revealing an explanation of this setting.

Note also that there is a search field at the bottom of this window. Suppose there were hundreds of settings and I wanted to find anything to do with optimization. If I type "optim" in the search field, the settings are whittled down to two, one of which is called Optimization level and the other of which has the word optimization in its explanation text. Very powerful stuff.


Figure 6. The inspector window, showing the build options for the Sketch (Upgraded) target.

The Groups & Files Pane

On the left side of the project window and just under the active target popup, you'll find the Groups & Files Pane. First in this list is the Files Group, which lists all the files that make up your project. If you click on this group, you'll see an alphabetical listing of all the project's files, including your Classes, Other Sources (such as main.m and any precompiled headers), Resources (Credits.rtf, Info.plist, InfoPlist.strings, and your nib files), Frameworks, and the Products produced by your project.

Figure 7 shows a default project, based on a Cocoa Document-Based Application template. The five sub-groups that make up the test Files Group are what you get when you create your project. As you might expect, you can create new subgroups (control-click on a group name and select New Group from the contextual menu and edit the name of any group (option-click on the name). You can also click and drag any group to move it up and down in the list or place it within another group in the hierarchy. Very intuitive. Very nice.


Figure 7. A sample project, showing the default Files Group.

The second group in the Groups & Files pane is the Targets group, which we've already discussed. The third group is your Executables group. By default, your project will contain a single executable (see the test executable, shown in Figure 7). Note that when we upgraded our target in the Sketch project, we also created a second executable, called Sketch (Upgraded).

The next group is the Errors and Warnings group. Click on this group and the errors and warnings from your last build are shown. Let's give this a try. In the Sketch project window, click and hold the first hammer icon in the toolbar, then select Build from the popup menu that appears.

Figure 8 shows the result of my Sketch build. This build generated 2 warnings, both of them in the file SKTDrawDocument.m, and 1 error, in the file Sketch_main.m (the warnings are actually part of the shipping Sketch project, the error is one I purposefully introduced). If you click on the Errors and Warnings group itself, you'll see a list of all the errors and warnings in the project. If you click on one of the file names in the group, you'll see a list of errors and warnings in that file. Finally, if you double-click on the Errors and Warnings group, you'll get a separate window with an upper split that lists all the errors and warnings in the project, and a lower split that allows you to edit the source code associated with the selected error or warning. Basically, the project window without the Groups & Files pane.

    The Errors & Warnings group is an example of what Apple calls a smart group. Smart groups are dynamic groups that change based on some action or rule. For example, the Errors & Warnings group is rebuilt each time you do a build. As you'll see when we get to the Find Results group a bit further along, smart groups are a very powerful part of Xcode's arsenal.


Figure 8. The Errors and Warnings group.

Next up is the Implementation Files smart group. This is an example of a rule-based smart group. To see what I mean, click on the Implementation Files group and then click on the Show info panel icon (an italic i in a blue circle) in the toolbar or type command-i to bring up the inspector window. Rule-based smart groups can be generated using regular expressions or simple patterns. As you can see in the inspector window shown in Figure 9, the Implementation Files smart group searches the project directory, recursively, to find all files that match the regular expression:

?*\.[mcMC]

In effect, this regular expression matches any file name that ends in one of ".m", ".c", ".M", or ".C", placing the list of matching file names in the Implementation Files smart group. To learn more about regular expressions, check out this link:

http://www.grymoire.com/Unix/Regular.html

O'Reilly also has a book on regular expressions (is there nothing they don't cover?) called Mastering Regular Expressions, 2nd Edition.

    When you click on the Implementation Files group, if the main area does not change, bring up the inspector window (command-i), click in the Using Pattern: text field, and hit enter. That should force the list to update. A tiny glitch. Probably fixed already!


Figure 9. The Implementation Files smart group, as seen in the inspector.

The NIB Files smart group is just like the Implementation Files group, except it uses simple pattern matching instead of regular expression matching, returning all files that match the simple pattern "*.nib". Smart groups are sweet.

But they get even sweeter. The Find Results smart group allows you to refine a search using the search field on the right side of the toolbar. Here's an example. Bring up the Sketch project and select Find in Project... from the Find menu. Enter draw in the Find: field and check the Ignore Case checkbox, then click Find (see Figure 10).


Figure 10. The Find in Project... panel.

A list of files should appear in the detail pane (the main part of the project window) and the status bar (the thin horizontal strip immediately below the toolbar) should say 1 of 294 selected. So our find just found 294 occurrences of the word "draw" in the project hierarchy. The results of this find were added to the Find Results smart group under the name draw.

Now let's refine our search a bit. Click on the draw subgroup (it may already be selected). In the search field (right side of the toolbar), type the word "white". You should see 2 matches, for the function NSDrawWhiteBezel, both in SKTGridView.m. You just did a search within a search. Very cool!

Next on our list is the Project Symbols smart group. Click on the Project Symbols group and a list of project symbols appears. As you might expect, you can use the search field to filter your symbols. If you click on the magnifying glass icon in the search field, a popup menu appears that lets you select from Search by All, Search by Symbol, Search by Symbol Type, and Search by Location (these are the three column headers in the detail area). Pick the type of search you want to do, then start typing. In Figure 11, I did a Search by Symbol Type and typed in "ma". This reduced the symbol list to show the project macros. Nice!


Figure 11. The Project Symbols group, with "ma" in the search field, and Search by Symbol Type selected in the search field popup menu.

Till Next Month...

I've been using Xcode like crazy since WWDC and I find the design very intuitive. Xcode does what I expect it to do. I am impressed, and even more so given that this is prerelease software. Yes, there are a few bugs, but for me they've all been minor. But be smart. Be safe. Backup your projects before you port them to Xcode. After all, prerelease is prerelease

There are a few interface elements I'd like to see cleaned up. Some are simple refresh issues. Others are behavioral. For example, I'd like to see the little triangle to the right of the magnifying glass icon in the search field only appear when there is a popup menu for that search field's context. And if there is a popup menu, how about including checkmarks next to any selected items so you can go back and see what the current settings are. Don't let these tiny nits deter you even one nanosecond. Xcode is an incredible leap forward.

Before I go, just a few quick things. First, wheel over to http://developer.apple.com and check it out. They've completely redone the site. I find it much easier to navigate now, with a lot more detail on the front page. I also wanted to thank (profusely) the folks at Apple who spent so much time answering my Xcode and Cocoa questions. A special shout out to the folks who staffed the OS X and Tools labs at WWDC. You rock!

Whelp, I'm out of space and out of time. Next month, we'll dig a little deeper into Xcode. There is so much more to cover. There's Code Completion, Zero Link, Fix and Continue, and Distributed Builds just to name a few. See you then...


Dave Mark is a long-time Mac developer and MacTech contributor. Author of more than a dozen books on various Mac-development topics, he's also a founding partner of the nationally syndicated Online Tonight and Net Music Countdown radio programs. All this and now he's got some fish!

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.