Detailed description of Targets in the XCode Project

Source: Internet
Author: User

XCodeEngineeringTargetsThe explanation is the content to be introduced in this article. I believe many people have noticed thatXCodeHas a Target concept, which is embodied in many places. For example, after opening a project, the list on the left hasTargetsIn the top menu of the project interface, there are multiple projects in the project that involve the Target. What is the Target?

Apple said,"TargetsThat define the products to build. A target organizes the files and instructions needed to build a product into a sequence of build actions that can be taken ."

In a simple understanding, we can think that a target corresponds to a new product (based on the same Code). But all of them have a piece of code. What should we do with a new product? Is this interesting?

In fact, this is not just a waste. Although the Code is the same, compilation settings (such as compilation conditions) and the resource files contained can be very different. therefore, even if the same code is generated, the product may be very different.

Let's take a few typical applications with multiple Targets, such as the full version and lite version; for example, the 20-off, 30-off, and 50-off versions of the same game; or, for example, changing resources and names for the same game can be sold as new games (hello, what are you teaching ...)

What are the same and what are the differences between Targets?

Since the same code is used to generate different products, what are the differences between different targets?

To solve this problem, let's take a look at the content specified by a Target.

From the list on the left side of XCode, we can see that a Target contains Copy Bundle Resources, Compile Sources, Link Binary With Libraries.

Copy Bundle Resources refers to the resource files included in the. app of the generated product.

Compile Sources indicates which source code is compiled

Link Binary With Libraries indicates which library files will be referenced during compilation

By using different settings in Copy Bundle Resources, we can make different products contain different Resources, including the main icons of the program, etc, instead of including the resources listed in XCode projects.

This is not all the content specified by a target. Each target can use an independent, different Info. plist file.

We all know that this Info. plist file defines many key content of an iPhone project, such as the program name and the globally unique id of the product.

In addition, different targets can define complete and differentiated compilation settings, from simple adjustment of Optimization Options to adding the compilation conditions used for Conditional compilation, so that the base SDK can be differentiated.

Create the second Target

Why is it the second one? Because the first one is the default Target after the project is created! (So much nonsense, drag it away ...)

There are multiple methods to create a target. We can copy a copy from the existing target, and then slightly Add the changes. We can also create a new target. But actually, the two methods are similar.

First, let's take a look at how to create a target using the replication method.

Create a target Using Replication

In the list on the left side of XCode, expand the Targets item. On the existing target, right-click and select "Duplicate", or select an existing target, in the top menu, select "Duplicate.

Now we get a new target, and a xxxx copy will be obtained in the Resource. plist. this new target is exactly the same as the original target, and the rest is some differentiated modifications. Let's talk about this later.

Create a new target

Similar to the copy method, we can right-click the menu in many places in the list on the left, and we can see that "New Target... "item, and in the Project on the top menu of the Project, you can also see this" New Target....

After clicking this button, we will first let you choose the target type. Since I have always been referring to the program itself, we will naturally choose Application. (for other items, please study them as you are interested, for example, we can extract parts of the program into a Static Library ).

Next, you will be asked to enter a new Target name, instead of generating a target name such as xxxxx copy by default in the copy method.

However, the generated Target is almost empty. Copy Bundle Resources, Compile Sources, and Link Binary With Libraries does not contain any content. The compilation settings are completely original.

You can drag the content to the target settings and adjust the compilation options to complete the Target configuration.

How to modify some content in Target

In fact, this part of content may also be used in non-multi-Targets projects.

Since the modification is basically completed in the project/compilation settings, no declaration is made in special cases. You can right-click the target to open the corresponding project/compilation settings, select get info.

Modify the generated product Name: the Product Name in the Packing segment

Info. plist File name: Info. plist File in the Packing segment. For example, if the copied target finds that xxxxx copy. plist is too silly, you can change it here.

Compile items: Add a User-Defined Setting (the gear in the lower left corner of the build page of Target "xxxx" Info to see this content), and enter it in Other C Flag, for example, to define a define value called LITE_VERSION, we can write "-DLITE_VERSION" or "-DLITE_VERSION = 1 ". then it can be used in the program

 
 
  1. #if defined(LITE_VERSION)   
  2. #else   
  3. #endif  

Such Conditional compilation is used to partially differentiate the code.

Some may remember the cracked version of the code I posted in the code area. One of the methods is to check info. plist is text or binary, so can we recommend a simulated cracking target to directly generate text info. plist for testing?

Of course you can. In the packing section, there is an item called "Info. plist Output Encoding ". The default value is Binary. We only need to select xml to generate the product. info. plist is a text style.

In addition, to add/delete files in Copy Bundle Resources, Compile Sources, and Link Binary With Libraries, you can select get info on the file to be modified and switch to the Target page, select the target to reference this file. for example, icon.png can be specified to the default target, while icon_lite.png can be specified to the target of lite verion.

Summary:XCodeEngineeringTargetsI hope this article will help you! For more information, see edit recommendations.

Original post address http://www.cocoachina.com/bbs/read.php? Tid-10972-fpage-0-toread--page-1.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.