< Previous PageNext Page > Hide TOC

Project Organization

Some of the design decisions you make when you first set up a project—such as how many targets you need for your software development effort—affect your entire development experience. This chapter provides tips for partitioning and arranging the code and resources for a product as you develop with Xcode. It also describes some of the features Xcode provides that let you group information for rapid and easy access. For instance, you can save commonly accessed locations as bookmarks or in the favorites bar, or you can document project items by adding comments to them.

In this section:

Software Development Tips
Dividing Your Work into Projects and Targets
Grouping Files
Saving Frequently Accessed Locations
Adding Comments to Project Items
General Preferences


Software Development Tips

The following are some general guidelines for developing your software in Xcode. In subsequent sections, you’ll get more detailed information to flesh out these tips.

Dividing Your Work into Projects and Targets

To develop software with Xcode, you are going to need at least one project, containing at least one target, and producing at least one product. Those are the basic structures you use for all your development.

Beyond that, there are no hard and fast rules for how you divide your work. For simple products or products that are closely tied together, you might use a single project with multiple targets. For large development tasks with many products, and especially with separate development teams, you’ll want to use multiple projects and targets, perhaps connected with cross-project dependencies.

The following sections provide additional information and tips on laying out your software.

Identifying the Scope

In partitioning your software, many decisions depend on the scope of the design goal and the number of products it requires. For example, if you’re working alone on a simple application, you can create a project for the desired application type (such as a Cocoa or Carbon application) and get right to work. Here are some of the decisions you might face:

Suppose, however, that you are working on a more complex software design, one that will be implemented by several individuals or development teams. Let’s say you are asked to create an application for an easy-to-use recording studio. You may already have components of this application, such as a shared library for presenting music tracks. As you refine the product specification, you identify other common tasks that might belong in a shared library, tool, or companion application. You determine that the main application should rely on Apple technologies to provide certain features, such as burning CDs or making the application scriptable.

Eventually, you identify a set of products to build, which gives you a good idea of the scope of the task. And that in turn can help you determine how to partition it into Xcode projects and targets.

Trade-Offs of Putting Many Targets in One Project

You can help determine whether to put many or all your targets in one project by considering some of the trade-offs involved. Here are some of the advantages of combining multiple targets in one project:

Here are some of the disadvantages of putting all your targets in one project:

Trade-Offs of Using Multiple Projects

There are also trade-offs in breaking up a software product into multiple projects and targets. Here are some of the advantages of using multiple projects:

Here are some of the disadvantages of having multiple projects and targets:

Grouping Files

Decisions about how to partition projects and their targets affect the design of your entire software development effort. It is also important that your work in a project be organized and accessible to you. Particularly in larger projects, the number of files can be daunting. To help arrange files into manageable chunks, Xcode lets you group them.

A group lets you collect related files together. A static group lets you group an arbitrary set of file, folder, and framework references in your project. A smart group, on the other hand, lets you group together files fitting a particular pattern or rule. This section shows you how to group files using static groups and smart groups.

Grouping Files into Static Groups

In the Groups & Files list, static groups look like folders, but don’t have to correspond to folders on the file system. You can instead arrange files into groups that make sense to you while working on them in Xcode. For example, in a project containing multiple targets, your project could store all the nib files in one folder and all the implementation files in another folder on the file system. And in the Groups & Files list, you could group the files according to target; that is, the nib files and implementation files for target A would be in one group, the nib files and implementation files for target B would be in another group, and so on. A group doesn’t affect how a target is built.

Creating a Static Group

You can create a static group in any of the following ways:

Adding Files to a Group

You can add files to a group at any time by dragging the file icons to the group’s folder in the Groups & Files list. A line appears to indicate where you are moving the files. Xcode automatically expands groups as you drag items to them.

Deleting Groups

When you remove a group from your project, you can choose whether to remove the files in that group from the project or simply ungroup the files.

Using Smart Groups

Smart groups are also represented by folder icons in the Groups & Files list; however, they are colored purple to distinguish them from static groups. As mentioned earlier, smart groups group files that adhere to a common pattern or rule. For example, you could define a smart group to collect all implementation files ending in .m or .c. When you make a change to your project that alters the set of files matching a smart group’s rule—for example, adding a .c file—the smart group automatically updates to reflect the change. You do not need to add files to a smart group yourself. In fact, Xcode does not allow you to drag files to a smart group.

Creating a Smart Group

To create a smart group, choose Project > New Smart Group. Then choose one of the following options:

Xcode adds a smart group of the selected type to your project and brings up the Smart Group Info window, which allows you to configure the group. Xcode provides templates for each type of smart group; it uses these templates to configure new smart groups with a default set of options. For example, the default Simple Filter Smart Group collects all files with *.nib in their name. The default Simple Regular Expression Smart Group collects all C, C++, Objective-C, Objective-C++, Java, and AppleScript implementation files in your project.

Configuring a Smart Group

To configure a smart group, select the group in the Groups & Files list and open the Smart Group Info window, shown in Figure 2-1.


Figure 2-1  Smart Group Info window

Smart Group Info window

Here is what the Smart Group Info window contains:

Viewing Groups and Files

As you learned in “The Project Window,” you have two ways to view the contents of your project. You can view the groups and files in your project in outline view to see a hierarchical representation of your project layout. Or you can view the groups and files in your project as a simple list, in the detail view. The detail view presents a flat list of all the files contained in the group selected in the Groups & Files list. For example, if you select your project in the Groups & Files list, the detail view shows all the files in the project. If you select an individual file in the Groups & Files list, only that file is displayed in the detail view. To view the contents of a group in the detail view, select that group in the Groups & Files list. See “The Detail View” for more information about the detail view.

Saving Frequently Accessed Locations

In any project, there are locations that you find yourself accessing again and again: files that you edit frequently, headers that you browse, even smart groups that you use often. Xcode lets you save locations that you access frequently and provides ways for you to jump to these locations. This section describes how to take advantage of bookmarks and the favorites bar to provide quick access to project contents.

Adding Items to the Favorites Bar

The favorites bar in the project window lets you save frequently accessed items and return to them quickly. To show the favorites bar, choose View > Layout > Show Favorites Bar.

To add an item to the favorites bar, simply drag it to the favorites bar in the project window. You can save any of the same locations you can bookmark, including files, documentation, URLs, and so forth. In addition, you can add smart groups and static groups to the favorites bar. The Groups & Files list can get quite long as you reveal the contents of more and more groups, scrolling the items at the bottom of the list out of view. You can add groups—including any of the built-in smart groups—to the favorites bar to quickly jump to that group in the Groups & Files list.

To reorder items in the favorites bar, drag them to the desired location; dragging an item off of the favorites bar removes the item from the favorites bar. To rename an item in the favorites bar, Option-click the item and type the new name. This changes the name of the entry in the favorites bar; it does not affect the name of the actual item that the entry represents.

To open a saved location, click it in the favorites bar. If the item in the favorites bar is a container, such as a group or folder, it is a pop-up menu that you use to navigate through the contents. Each of the items in the favorites bar serves as a proxy for the actual item. Thus, Control-clicking the item brings up the item shortcut menu, which allows you to perform operations appropriate for the selected item.

Defining Bookmarks

Another way that Xcode lets you navigate your project and provide easy access to the information you need is with bookmarks. If you have files or locations in your project that you access often, you can bookmark them and return to those locations at any time simply by opening the bookmark.

To create a bookmark, select the location you want to bookmark and choose Edit > Add to Bookmarks.

Xcode automatically names some bookmarks. For items such as symbols, Xcode prompts you for the name of the bookmark; you can enter a name to help you remember which location the bookmark indicates, or you can use the name Xcode assigns. You can bookmark project files, documentation, URLs, and so forth.

You can see the bookmarks in your project in several ways:

Adding Comments to Project Items

To help you keep track of your project contents, you can write comments and associate them with any of the items in your project. Xcode remembers these comments across sessions. In this way, you can document your project and its components, keep design notes, or track improvements you still wish to make. This is especially useful if you are working with large or complex projects that have many pieces, or if you are working with a team of developers and have multiple people modifying the project.

For example, imagine a large project containing targets that build a suite of applications, a framework used by each of those applications, a command-line tool for debugging, and a handful of plug-ins for the applications. With such a large number of targets it might be hard to keep track of exactly what each of the products created by those targets does. To make it easier to remember what each of them does, you could add a short description of the product that it creates to the target’s comments. This also aids others who may be working on the project with you; if they can read the comments, they can quickly get up to speed with the project and easily learn about changes made by other members of the development team.

To add comments to a project item:

  1. Select that item in the Groups & Files list or in the detail view and open its Info window.

  2. Click Comments to open the Comments pane.

    This pane contains a single text field into which you can type any information you wish. To add comments, click in the Comments field and type your entry. You can also link to additional resources from the Comments pane; hypertext links, email addresses and other URLs are actionable in this field.

You can add comments to any project item except smart groups, including projects, targets, files, and executables. You can view comments you have added to project items in the detail view and you can search the content of those comments using the search field. If the Comments column is not already visible, use the shortcut menu of the detail view header to display it.

General Preferences

The General pane of Xcode preferences lets you control general environment settings for the Xcode application, such as your project window configuration and windowing preferences. Figure 2-2 shows the General pane.


Figure 2-2  General preferences pane

General preferences pane

Here is what the pane contains:



< Previous PageNext Page > Hide TOC


© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-06)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.