1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình Wrox Professional Xcode 3 cho Mac OS part 46 docx

8 172 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 8
Dung lượng 2,03 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

In between these two extremes are target types such as aggregate targets and the legacy Jam - based targets.. Native Targets The native target types in Xcode are Application, Command -

Trang 1

346 ❘CHAPTER 16 TARGETS

Target Product

Most targets produce a product The kind of product produced is determined by the type

of the target Application targets produce applications, library targets produce libraries, command

-line targets produce UNIX executables, and so on A special type of target, called an aggregate

target, doesn ’ t produce anything itself It exists solely to group other targets so they can be treated

as a single target In other words, it ’ s a target that “ produces ” other targets

TARGET TYPES

It ’ s diffi cult to classify target types in Xcode neatly, because the types form a kind of spectrum However,

the spectrum of target types can be roughly divided between the native and non - native targets Native

targets are at one extreme of the spectrum They are sophisticated, are tightly integrated into Xcode,

are highly confi gurable, have a fl exible number of build phases, and produce complex products (like

frameworks) At the other extreme is the non - native external target An external target simply launches

some external process with the understanding that said process will do whatever is necessary to build

the target Xcode doesn ’ t know what an external process will do, what fi les it depends on, or even if it

produces anything An external target has no build phases and is not confi gurable (from within Xcode)

In between these two extremes are target types such as aggregate targets and the legacy Jam - based

targets The sophistication of these target types varies They may have some of the same parts as native

targets but are usually simpler and are not as tightly integrated into Xcode

FIGURE 16 - 4

Download at getcoolebook.com

Trang 2

The type of a target is displayed in the General tab of the target ’ s Info window You cannot change the type of a target If you fi nd you are using the wrong target type, you must delete the target and create a new target of the correct type

Native Targets

The native target types in Xcode are Application, Command - Line Tool, Dynamic Library, Static Library, Framework, Bundle, Kernel Extension, and IOKit Kernel Extension Native targets are easily identifi ed by their colorful and emotive target icons Application targets have a small application icon, Command - Line Tool targets are represented by a little terminal screen, Framework targets have a toolbox icon, and the remaining targets appear as plug - ins Native targets usually have a full complement of parts (build phases, settings, rules, and dependencies) Native targets that include an Info.plist fi le in their product also include a set of properties See the “ Properties ” section, later in this chapter, for more details

External Targets

An external target defi nes a build target that is produced by some external process This was designed to permit Xcode to integrate with existing workfl ows based on build tools like Make or Ant The target is little more than a placeholder It specifi es the tool that will perform the build and the arguments that are passed to it, as shown in Figure 16 - 5 Xcode has no knowledge of what fi les the process requires, what it does, or what it will produce You cannot add project fi les or build phases to

an external target The section “ Java and Other Jam - Based Targets ” has more information

FIGURE 16 - 5

Trang 3

348 ❘CHAPTER 16 TARGETS

Aggregate Targets

Aggregate targets, as the name implies, group several targets together using dependencies An

aggregate target that depends on several different targets can be used to build all of those targets as

a unit Suppose you have developed a suite of BSD command - line tools, each produced by a separate

target To build all of these tools at once, you would create an aggregate target, say it ’ s named “ Tools, ”

that depends on all of the Command - Line Tool targets Now whenever you want to build all of the

tools, you simply build the one Tools target Likewise, you might have applications or other projects

that depend on having all of those tools built Making those targets dependent on the single Tools

target is much easier to maintain than adding each tool target to every target that depends on them

Aggregate targets can also be used for utilitarian purposes Aggregate targets don ’ t produce a

product, but they can still be made to do useful work by adding Copy Files or Shell Script build

phases These build phases are executed whenever the target is built, regardless of whether it has any

dependencies See the section “ Build Phases ” for more details about adding build phases to a target

Java and Other Jam - Based Targets

Xcode still includes support for the legacy Jam build system, which it inherits from its predecessor,

Project Builder A Jam - based target is a non - native target; the target ’ s build logic is external to

Xcode, and the target ’ s confi guration isn ’ t integrated with the rest of Xcode Jam - based targets are

used to implement the external and aggregate target types, and to support legacy targets that were

created in Project Builder or obsolete versions of Xcode

Using Jam - Based Targets

All Jam - based, non - native targets (as well as the aggregate targets) appear as a red bull ’ s - eye in the

Targets smart group Editing the details of some Jam - based targets is different from editing native

targets (you confi gure native targets using the different panes in the target ’ s Info window) All

Jam - based targets are confi gured using a target editing window, like the one shown in Figure 16 - 5

See the “ Jam - Based Target Editor ” section later in this chapter for the details

Upgrading Jam - Based Targets

Except for the external and aggregate targets, you ’ ll probably want to upgrade any other Jam - based

targets to native targets whenever possible

Convert your Jam - based targets into a native target using either the Project ➪ Upgrade to Native

Target or the Project ➪ Update All Targets in Project to Native command These commands are

enabled whenever Xcode detects legacy targets originally created with Project Builder or an old version

of Xcode These commands run a conversion process on either the selected Jam - based target or all

non - native targets in the project, respectively Not all Jam - based targets can be converted to native

targets If the conversion is unsuccessful, a report explaining why is produced If successful, a native

target with the same name plus the suffi x “ (Upgraded) ” is created and added to the project Ensure that

the new target functions correctly before deleting the original target The conversion process does not

create new target dependencies, so any targets that depended on the original target have to be edited

The conversion also results in a report, an example of which is shown in Figure 16 - 6 In addition to

making a new target, the conversion process may duplicate project fi les The example in Figure 16 - 6

shows that a duplicate of the Info - StockMarketTicker.plist fi le was made and was named

Download at getcoolebook.com

Trang 4

FIGURE 16 - 6

FIGURE 16 - 7

original target You may also want to rename the new .plist fi le, which requires editing the new target ’ s settings to match

CREATING A TARGET

Creating a target is much like adding a new fi le to your project Choose the Project ➪ New Target command Alternatively, Right/Control+click the Targets group and choose the Add ➪ New Target command Either method presents the New Target assistant, shown in Figure 16 - 7

Trang 5

350 ❘CHAPTER 16 TARGETS

Choose a target template from the list You ’ ll immediately notice that there are far more templates

than target types Many of the templates produce targets of the same type, but are preconfi gured for

different purposes For example, the Aggregate, Copy Files Target, and Shell Script Target templates

all create an aggregate target with no build phases, one Copy Files build phase, or one Run Script

build phase, respectively Because build phases can be easily added or removed, the differences

among these templates are trivial Choose a target template that is as close as possible to the type of

product you want to produce

What is of utmost importance is to create a target of the correct type, because you cannot change

the type of the target later If you end up with a target of the wrong type, your only option is to

delete the target and start over The rest is just details

After you ’ ve selected the target template, click the Next button The assistant presents you with a

dialog box to enter a name for the target and select the project you want it added to, as shown in

Figure 16 - 8 The product produced by the target initially has the same name as the target You can

alter both the target name and product name later, but to avoid confusion, I suggest keeping them

the same whenever practical If you have more than one project open, select the project that will

receive the new target from the Add to Project menu Click the Finish button

FIGURE 16 - 8

Some templates will also add one or more support fi les to your project For example, almost any

target the produces a bundle (application, framework, plug - in, unit test, and so on) will also need

Target Template Groups

Target templates are organized into groups to make them easier to locate Start by choosing

the group that most closely describes the type of development you are doing (Cocoa, Cocoa

Touch, BSD), and then choose your template Be careful of similarly named templates The

Application template in the Cocoa group produces a signifi cantly different product than

the Application template in the Cocoa Touch group

Download at getcoolebook.com

Trang 6

Cocoa Touch Templates

Templates in the Cocoa Touch group create targets suitable for producing iPhone applications, static libraries, and unit tests These are similar to the targets in the Cocoa group, but have different compiler settings and link to different frameworks

Application A native iPhone or iPod Touch application target The template adds an

Static Library A native Static Library target that produces a static library fi le

Unit Test Bundle A unit test bundle, linked to the Foundation framework Also adds an Info

unit testing

Cocoa Templates

Use these targets, listed in the following table, to produce Mac OS X applications, libraries, and shell tools

Application A native Application target that produces an application bundle

linked to the Cocoa framework This template adds an Info

Dynamic Library A native Dynamic Library target that produces a .dylib library fi le,

itself linked to the Cocoa framework

Framework A native Framework bundle target This template adds an Info

Loadable Bundle A native Bundle target that produces a generic bundle linked to

the Cocoa framework This template adds an Info.plist fi le to your project

Shell Tool A native Command - Line target that produces a BSD executable

binary

Static Library A native Static Library target that produces a static library fi le, itself

linked to the Cocoa framework

Unit Test Bundle A native Bundle target confi gured to produce a unit test written

using the Cocoa framework See Chapter 20 for more information about unit testing This template adds an Info.plist fi le to your project

Trang 7

352 ❘ CHAPTER 16 TARGETS

The Loadable Bundle is the catch - all template for creating virtually any kind of bundle If you can ’ t

fi nd a template for the particular type of bundle (application, plug - in, and so on) that you ’ re trying

to create, start with the Loadable Bundle template

Application Plug - In Templates

The only template currently in this group is the Automator Action template:

Automator Action A native Bundle target that includes a Compile AppleScript Files phase,

suitable for producing Automator Action bundles This template adds an

BSD Templates

The BSD templates, listed in the following table, create targets that produce fl at BSD executable or

library fi les

Dynamic Library A native Dynamic Library target that produces a .dylib library fi le

Object File A native Object File target that compiles a single module using the BSD APIs

Shell Tool A native Command - Line target that produces a BSD executable binary

Static Library A native Static Library target that produces a static library fi le

System Plug - Ins Templates

The two templates, listed in the following table, create the specialized targets used to produce kernel

extension bundles

Generic Kernel Extension A Kernel Extension target that produces a kernel extension bundle

IOKit Driver An IOKit Kernel Extension target that produces a kernel extension

bundle

Other Templates

The targets listed in the following table create empty or placeholder targets None of these targets

produces a product, although the process launched by an external target is expected to build

something

Download at getcoolebook.com

Trang 8

TARGET DESCRIPTION

Aggregate An empty Aggregate target

Copy Files An Aggregate target with a single Copy Files build phase

External A Jam - based External target External targets run some external process

(like make) to build the target They cannot have build phases

Shell Script An Aggregate target with a single Run Script build phase

Legacy

If you upgraded an earlier version of Xcode, your installation may contain additional target templates that have since been removed from the Xcode Developer Tools These might include Java Applet, Carbon, and other deprecated targets For the most part, Xcode still supports these legacy target templates, but may not in the future

Duplicating Targets

You can also create a new target by duplicating an existing one This is especially useful if you need

a new target that is very similar to one that already exists Select the target in the Targets smart group In the Right/Control+click contextual menu choose the Duplicate command A duplicate

of the target is created with the suffi x “ copy ” appended to the target ’ s name Note that the new target is an exact duplicate except, of course, for its name If the original target produced a product, the new target will produce the same product Assuming you want the targets to build separate products, remember to edit the settings of the target so the two products don ’ t overwrite one another

Deleting Targets

To delete a target, select the target in the Targets smart group Press the Delete key or choose Delete from the Right/Control+click contextual menu Xcode presents a warning that removing a target will also remove the reference to it in any targets that depend on it Click the Delete button to acknowledge the warning and delete the target

BUILD PHASES

Build phases defi ne the steps that must occur in order to build a target Build phases tend to paint

with a broad brush Targets typically have one Compile Sources build phase that compiles all of

the source fi les for that target, even if that includes source fi les from many different languages

Consequently, targets rarely have more than three or four build phases

Use the disclosure triangle next to the target ’ s name in the Targets smart group to reveal the build phases for the target, as shown in Figure 16 - 9 The list of fi les on which a build phase will operate, or depends, is referred to as the phase ’ s input fi les Selecting a build phase lists the input

Ngày đăng: 04/07/2014, 06:20

TỪ KHÓA LIÊN QUAN