What are "targets" in Xcode?
Asked Answered
C

2

9

I have seen a lot of things about 'targets' while working with xcode. when i click on the project icon (blue, in xcode 4.2) i see 'Targets' in the middle pane with my file name under it.

What does that mean? and can I add more 'targets' to my project? If yes, what would that mean?

I have this: http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Targets.html

but i didn't understand a thing

Cathexis answered 21/8, 2012 at 13:42 Comment(0)
F
14

A target basically defines what it is you are building and how you are building it. You can add more targets if you would like to build more than one thing. This usually makes sense if you need to build several related things from the same project.

For instance, you might want one target for a full, paid version of an application, and another target for a reduced, free version of an application. Both targets would include much of the same code and resources, but some of the settings would be different and you might have different files included with each.

Frangos answered 21/8, 2012 at 13:52 Comment(0)
M
1

Targets are simply different ways of building a product. You have your source files, and you have your output, and there are several ways that you can get from A to B.

An Xcode project may contain a number of source files which can be built do produce a number of different products.

For example, you could build an executable using some of the files, or you could build a library (Framework) from some of the files, or a unit test library, or with different build flags.

Most projects will have a single target, but some are more complex than others.

Mydriatic answered 21/8, 2012 at 13:47 Comment(5)
It's probably not a good idea to describe targets as configurations, because configurations are something different in Xcode.Frangos
you mention libraries. so can i add a library 'project (?) as my target, and build it? because it requires different commands, is there a different method to add a target? or is it that i can just select the files from the available files in the workspace (under the compile sources in build phases probably) but the building and execution wll follow the same command?Cathexis
If you want to make a library, create a new Dynamic Library, Static Library or Framework target then add the relevant files to it.Mydriatic
okay. now i see the 'new target..' option in file menu. So if I make a library as my target, then whenever i build and run my project as a whole, all my targets would be built and executed?Cathexis
Which targets get built depends on the scheme that is active, but if you have one target which is depended on by another, you should just add it to the target dependencies instead of altering your scheme.Frangos

© 2022 - 2024 — McMap. All rights reserved.