Xcode defi nes several smart groups, as listed in the following table: SMART GROUP CONTENTS Targets The targets defi ned in the project.. These groups are actually just predefi ned custo
Trang 1Despite its name, the All - In - One style does not force everything into a single window You can still
cause selected source fi les to open in separate windows for more convenient editing Additionally,
Info and Quick Help windows are always separate, regardless of the layout style you are using
Changing the Layout
Xcode ’ s layout style is global After you have set it, it applies to all projects that you open To
change Xcode ’ s layout style, choose Xcode ➪ Preferences, and click the General (leftmost) icon at
the top of the window (see Figure 3 - 6)
FIGURE 3-6
The global layout style is selected with the Layout pop - up menu Other options control the behavior
for edit panes, whether projects are automatically reopened when Xcode is launched again, and
whether open windows are restored when a project is reopened
The layout style cannot be changed while there are any open windows that are infl uenced by Xcode ’ s layout style If the Layout option in the preferences window is disabled, close all projects and utility windows until it becomes enabled
The next few sections explain the details of the project window and how the layout styles infl uence
their layout and navigation
GROUPS & FILES
All of the components of your project are represented as icons in the Groups & Files pane of your
project window Icons with a small grey expansion triangle next to them indicate a group of items
Groups contain items and sometimes other groups
Trang 2The very fi rst group is the project structure
group , or just project group This has the same
name as the project and contains all of the project ’ s assets The remaining groups are called
smart groups Smart groups change to refl ect
the state of the project Figure 3 - 7 points out the source and smart groups in a layout
Search for something and the search and its results appear in the Find Results group for future reference Edit a fi le checked out from source control and it appears in the SCM group
Check in the changes and it disappears again
You can expand or collapse the contents of any group by clicking the small triangle next
to the group ’ s icon Holding down the Option key when expanding or collapsing expands or collapses all subgroups as well
Project Structure Group
The most fl exible group is the project structure group Within this group, you add the source assets (source fi les, image fi les, Interface Builder documents, property lists, and so on) that will be used to build your project All of the groups in the project structure group are generically
referred to as source groups These can be organized into any arbitrary arrangement of subgroups
that you like When you create a project, Xcode automatically creates source groups for Classes, Other Sources, Resources, Frameworks, Products, and possibly others depending on the project template Within the Frameworks groups you ’ ll usually fi nd subgroups for Linked Frameworks and Other Frameworks
How many source groups you create, their names, and how you organize them is entirely up to you Xcode does not impose any kind of organization or convention when it comes to the project structure group You are free to put a movie fi le in the Classes groups or rename the Classes group
to “ Wonkavator ” You can just as easily move all of your assets to the top - level project structure group and delete all subgroups This is not a bad idea for very small projects, because many small groups can just get in the way
Although you generally have carte blanche to organize the source groups however you see fi t, there is one exception: the Products subgroup Although Products appears to be just another source group, it ’ s actually a smart group.
FIGURE 3-7
Trang 3Smart Groups
The remaining groups in the project window are the smart groups If you have used smart groups
in iTunes or Mail lately, this concept will be immediately clear A smart group contains items that
refl ect some property or information about your project, and have a fi xed or restricted structure
Files or items that meet that criterion appear in the group automatically, and disappear as soon as
they no longer qualify Xcode defi nes several smart groups, as listed in the following table:
SMART GROUP CONTENTS
Targets The targets defi ned in the project Expand a target to reveal its
build phases See Chapter 13
Executables Executable programs produced by the project
Find Results The results of the last several searches that were performed
Bookmarks Bookmarks you have created
SCM Pending Source Control actions for this project See Chapter 21
Project Symbols The symbols defi ned in the project
Breakpoints The debugger breakpoints set in the project This group is not
shown by default
Implementation Files All of the source fi les (.c, cpp, m, mm, java, sh, and so on) in the
project
Interface Builder Files All of the NIB documents in the project
Organizing Groups and Their Contents
Reorder your source or smart groups by dragging them to a new position in the list Reorganize
source groups and source items by dragging them to a new position in the source group, or dropping
them into another source group A drop indicator will tell you if are you about to drop the item(s)
adjacent the group, or inside it
You can create a new, empty source group by selecting a source group or fi le and choosing
File ➪ New Group from the main menu, or you can Right/Control+click on a source item and
choose Add ➪ New Group A new group with the name New Group is created inside the selected
source group, or in the same group as any selected fi le, as shown in Figure 3 - 8 Edit the name of the
new group and press Return
Trang 4You can gather an arbitrary set of fi les or groups and move them inside a newly created group in
a single step: select the items and choose the File ➪ Group, or Right/Control+click and choose the Group command A new group is created, and all of the selected groups and fi les are placed inside the new group You have only to name the new group
You can rename any source group or fi le by fi rst selecting it and clicking once on the item ’ s name
You can also Right/Control+click an item and choose Rename
Finally, you can delete a group in one of two ways The fi rst, and most obvious way, is to choose Delete from either the Edit menu or the Right/Control+click contextual menu This deletes both the group and its contents If the group contained fi le or folder references, you get a confi rmation dialog box asking you if you want to delete just the references or the actual fi les See Chapter 5 to learn about references
To delete a group without deleting its contents, select a group and choose the Ungroup command
from the Right/Control+click contextual menu (there is no main menu command for this) Ungroup dissolves the group and replaces it with the items it previously contained
Showing and Hiding Groups
You are free to alter which top - level groups are visible in your project window For example, if you are not using source control you may want to hide the SCM group
FIGURE 3-8
Trang 5before deleting it This is somewhat misleading,
because the group is not “ deleted ” in the
strictest sense Check the group in the
Preferences menu again and it reappears
When using the Condensed layout, you have
three sets of groups, defi ned by the Files,
Targets, and Other tabs above the group list
Each set is independent of the others, and you
can add or remove groups from any tab I fi nd it
convenient to have the Bookmarks group in the
Files tab, because most of my bookmarks are
shortcuts to places in my source code Show or
hide the groups that make sense to you
In the Default and All - In - One layout styles, you
can also have multiple views of your groups
In these two layout styles, Xcode places a split
-pane control just above the group list scroll bar
Click the split pane icon, as shown in Figure
3 - 9, to split the list into two lists You can now
alter which groups appear in the upper and
lower panes independently To return to one list
again, click the join pane icon just below the
split pane icon of the list you want to discard
Unfortunately, Xcode does not remember which
groups were visible in the second list the next
time you re - split the pane If you spend time
customizing your groups, it ’ s best to leave the pane split, minimizing one or the other as desired
You can also, rather erroneously, select any top - level group and apply the Delete command as you
would a source group The Delete command merely hides the group and is equivalent to unchecking
it in the Preferences submenu
Making Your Layout the Default Layout
After you ’ ve spent some time setting up and customizing the organization, panes, and columns of
your project, you can save that layout as the new default for all new projects Here ’ s how:
1. Customize the layout and organization of a project
2. Choose the Windows ➪ Defaults command
3. Click the Make Layout Default button
FIGURE 3-9
Trang 6When using the same layout style, all new projects will have the same size, layout, and organization that your current project has right now
If you ’ ve completely trashed the default layout, or you inherited one that you dislike, you can reset the new project layout to the factory settings To reset the layout, choose the same command but click the Restore To Factory Default button instead Note that these two commands only apply to new projects using the current Xcode layout style
Customizing the Implementation and Interface
Builder Files Smart Groups
The Implementation Files and Interface Builder Files smart groups automatically collect all of the source fi les that match a particular naming convention These groups are actually just predefi ned custom smart groups, which you can create yourself The next section will show you how You edit the criteria of these two by selecting one and choosing the Get Info command Get Info is available from the File menu, the Right/Control+click contextual menu, and from the toolbar The Info window for the Implementation Files group is shown in Figure 3 - 10
FIGURE 3-10
The really useful settings here are the Start From and Using Pattern settings You can limit the scope
of the smart group ’ s search by setting the source group that it searches, and whether it searches just the fi les in that group or it and all of its subgroups The Using Pattern establishes the fi lename pattern that will cause fi les to appear in the smart group If you want header fi les to appear, but not script fi les, edit the pattern accordingly You have the choice of using a shell - like globbing pattern or
a regular expression The changes you make affect all projects
The rest of the options are really only applicable when creating and customizing your own smart groups, and should probably be left as they are
Trang 7groups pre - defi ned: The Implementation Files group and the NIB Files group that were described in
the previous section
Custom smart groups come in two fl avors: Simple Filter smart group and Simple Regular Expression
smart group The Filter fl avor matches fi les based on fi le name “ globbing ” used in the shell — where
the pattern *.c matches all C source fi les The Regular Expression fl avor matches fi les using regular
expressions — the pattern \.[ch]p{0,2}$ matches fi le names ending in .c , .h , .cp , .hp , .cpp , or
.hpp See Chapter 8 for an overview of Regular Expressions The “ Searching Lists ” section of that
same chapter has a brief description of globbing patterns
Creating a Simple Smart Group
To create your own smart group, choose either the Project ➪ New Smart Group ➪ Simple Filter
Smart Group or the Project ➪ New Smart Group ➪ Simple Regular Expression Smart Group
command A new simple smart group is immediately created, its Info window open and ready to
edit There is no opportunity to cancel here If you didn ’ t want to create the smart group, delete it
(see the “ Deleting Custom Smart Groups ” section)
Defi ning a Smart Group
In the Info window, edit the name under which the group will appear in the project window Click
on the Choose … button next to the image, or drag an image into the icon preview, to provide the
group with something more evocative than the generic “ gear folder ” icon
Start From chooses where the smart group looks for fi les that match the pattern Project is the
default, and refers to the top - level project structure group You can also choose to restrict
the search to a specifi c group within the project The Recursively check box causes the
Smart Group to search all subgroups of the Start From group for matches
The Using Pattern fi eld is either the wildcard or regular expression pattern that will be used to
match fi les If you selected to create a Simple Filter Smart Group, Wildcard will be selected If you
selected to create a Simple Regular Expression Smart Group, Regular Expression will be selected
You can turn a Filter group into a Regular Expression group, and vice versa, at any time by selecting
the other radio button
The Save For menu determines if the Simple smart group you just created will appear in all projects
opened on your system, or only the current project The All My Projects setting is convenient for
Smart Groups you plan to use over and over again, as you can elect to use it in any project just by
revealing it in the project ’ s group list
Be very careful when creating simple smart groups for all projects There is no way to individually delete smart groups you ’ ve created A procedure to delete all
of the global smart groups is described in the next section, but if you want to delete some and preserve others, you will need to reconstruct them
Trang 8Also, be careful when saving a smart group for all projects that have a Start From location that is not the top - level project structure group There is no clear rule for determining which group will actually be searched in other projects.
Those projects might not have a group with that name, or they once did and the group was renamed, or the group has been moved to some other part of the group hierarchy Any of these conditions can cause a global smart group to search the wrong group for fi les When you ’ re creating smart groups that you intend to use in other projects, stick to the top - level project structure group
You can later open the Info window for any smart group and edit its defi nition
One caveat about smart groups is that sometimes they aren ’ t very smart Although they will usually pick up fi les that you add to a project, they often fail to update if you rename or remove them from the project Closing and opening the project will refresh the list
Using Custom Smart Groups in Other Projects
System - wide smart groups that you defi ne in one project won ’ t automatically appear in other projects Use the technique described earlier in the “ Showing and Hiding Groups ” section to add (or remove) your global custom smart group to another project
Deleting Custom Smart Groups
One unfortunate omission from the Xcode user interface is the ability to delete smart groups that you ’ ve created Like the predefi ned smart groups, an attempt to delete them only hides them in the list Even more irksome is that the data structures used to store smart group defi nitions are opaque, making it impossible to selectively delete smart groups What you can do is delete all of the smart groups saved in an individual project, or all of the global smart groups available to all projects If you have smart groups that you want to save and others that you want to delete, you will need to write down the settings for the ones you want to save and recreate them afterwards
To delete all of the smart groups saved in an individual project, fi rst close the project Select the project ’ s fi le icon in the Finder and use the Right/Control+click contextual menu to choose Show Package Contents Inside the .xcodeproj package, you will fi nd a series of fi les beginning with your account ’ s short user name where Xcode preserves the layout and window preferences for each user The fi le youraccount pbxuser contains the smart group defi nitions that you ’ ve saved
in this project Open the fi le in a text editor, such as TextEdit or BBEdit, and delete the line that begins with com.apple.ide.smrt.PBXUserSmartGroupsKey Alternatively, this could also be accomplished via the following command line in the Terminal:
james$ cd ~/Desktop/Explore\ Layout/Explore\ Layout.xcodeproj/
james$ mv james.pbxuser james.pbxuser.bak
Trang 9Delete this element and save the fi le The next time you launch Xcode, it will recreate the default
Implementation Files and NIB Files groups All other user - created smart groups will be gone
DETAILS, DETAILS
Now that you ’ ve learned to organize, customize, and navigate the top groups of your project, you ’ re
going to start digging into the details of those groups and what they contain Details about the
content of groups are displayed in a table called the details list The columns of the table display
properties about each item
In the Default and All - In - One layout styles, the details list is displayed in a pane on the right side
of the window, as shown in Figure 3 - 12 The Condensed layout style does not include a details pane
in the project window
The details pane shares its side of the window with an editor pane If the details list is not visible,
choose View ➪ Detail or View ➪ Zoom Editor Out to reveal it You can also drag the divider
between the details list and the editor pane
FIGURE 3-11
To delete all of the smart groups saved for all projects, fi rst quit Xcode Using the Property List
Editor (you will fi nd this in the /Developer/Applications/Utilities folder), open the
element with the key com.apple.ide.smrt.PBXUserSmartGroupsKey.ver10 , shown in Figure 3 - 11