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

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply 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
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
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
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.