- Getting to Know Xcode
- Goodbye "8220;Hello, World"
- Hello, App Development for Mac OS X and iOS
- Getting Started with Xcode
- Using the Navigator
- Using Editors
- Working with Assistant
- Getting Help in an Editor Window
- Using UtilitiesInspectors
- Using UtilitiesLibraries
- Using the Text Editor
- Using the Organizer Window
- Summary
- Workshop
- Activities
Using Utilities—Libraries
The bottom pane of the utility area is for libraries. These are collections of items that you can add to your apps just by dragging them to the appropriate place in an editor.
More information on libraries is included in Hour 11, p. 189.
The selector bar at the top of the library pane lets you choose from four libraries:
- File templates—[ctrl][option][command]1
- Code snippets—[ctrl][option][command]2
- Objects—[ctrl][option][command]3
- Media—[ctrl][option][command]4
You can also use the View, Utilities submenu to select the library you are interested in. If the Utilities submenu is hidden, use the View menu or the rightmost of the three View buttons at the upper-right of the workspace window to show it.
Figure 1.29 shows the general components of the library pane. At the top of the library pane, a pop-up menu lets you navigate to sections within that library. To its right, buttons let you display the contents of that library as icons or in a list. The icon view can make finding images or objects such as graphic elements very fast; for other items such as code snippets, the list view is better.
At the bottom of the library pane, a search field lets you filter the library shown above it.
When you select an item in the library, a description appears floating over the editor area, as shown in Figure 1.30. This description is generally somewhat lengthier than the summary in the library list.
File Templates Library
These file templates give you a headstart for whatever type of code you want to write. The pop-up menu at the top of the library pane lets you choose between iOS and Mac OS X file templates.
Figure 1.29 Use the library pane to take advantage of existing code, objects, and media.
Figure 1.30 Select an item in the library to see its description.
You select the appropriate file template from the file template library and drag it into the project navigator, as shown in Figure 1.31.
Figure 1.31 Use a file template.
You can also use file templates by choosing File, New, New File, as shown in Figure 1.32. The templates in this interface are shown grouped by their SDK and area of functionality. However, as you can see in Figure 1.32, by comparing the descriptions of NSManagedObject subclass in the library and in the sheet, they are the same. The menu command gives you the organization by SDK and area, while the library provides you with the ability to search with the filter at the bottom of the pane. The choice is yours.
Code Snippet Library
Code snippets can only be dragged into text editing files. They provide common examples and templates. The pop-up menu lets you choose from iOS, Mac OS X, and your own snippets (which you can add).
If you select a code snippet, its code appears as shown in Figure 1.33. Sometimes, if you have just forgotten a small piece of syntax, this refresher is enough and you do not have to worry about actually dragging the snippet into your file. Other times, the snippet gets you started with your own programming.
Figure 1.33 Select a snippet to see its contents.
Object Library
The Object library contains objects you use in building interfaces. This includes visible interface elements, such as views and buttons, as well as objects that work behind the scenes, such as view controllers.
- See Hour 11, p. 189, and Hour 12, “Finding Your Way Around Interface Builder: The Code Story,” p. 209, for more details on developing your app’s interface.
Media Library
The Media library brings together media files (icons, sounds, and images) from your workspace or from the system. Particularly when you have large projects, this helps you keep things organized. It also means that in creating your file groups, you can organize them functionally rather than putting all media files in one group and all code files in another.