iOS Xcode Project And Target Structure Example

After you create an Xcode project for iOS app development, you must wonder about the files under the project folder. And besides that, you also do not know one Xcode project can have multiple targets, one target defines a series of build-related settings information ( for example target deployment iOS version, target device, etc) for the iOS app. And you can define multiple targets in one Xcode project to create multiple iOS apps with different build settings data. This article will introduce all those you care about. If you are a very beginner, please read iOS Swift Hello World Example.

1. Xcode Project & Target Introduction.

  1. After you create the Xcode project ( use Single View App template ), you will find there is a subfolder in the project navigator, the subfolder name is the same as the project name.
  2. If you click the project name in the Xcode left navigator panel, you can see the project default target ( the target name is the same as the project name ) under the TARGETS item in the center editor panel. The below picture contains two Targets because I just create another target which name is Target1.
    ios-xcode-project-target-panel
  3. If you click the project HelloWorldSwift under the PROJECT item in the center editor panel, you can see the project information in the right pane as below. You can change settings information such as Deployment Target etc. Below is the default build settings for this project.
    ios-xcode-project-information-panel
  4. If you click one target under the TARGETS item, it will display the target-related build settings in the right pane, you can also change settings under the Deployment Info section such as choose a different device and device orientation. The target settings data is inherited from project settings.
    iox-xcode-project-target-information-panel

2. How To Create Target In Xcode.

  1. Now you should have understood the difference between Xcode project and target. Next, I will tell you how to create a target in Xcode.
  2. Click File —> New —> Target in the Xcode top menu bar.
  3. Select iOS —> Single View App in the popup template dialog.
  4. In the next dialog, input product name Target1, and select project HelloWorldSwift, the language should select Swift.
  5. When the process is finished, you can see both HelloWorldSwift and Target1 under the project. They has the same source files because of using same template.
  6. When you run the project, you can select which target to run at the top Set the active scheme drop-down list as below.
    ios-xcode-run-different-target-drop-down-list
  7. Also, the two target’s built binary files can be found under the Products folder in the left project navigator. So each target is a product in Xcode.

3. Xcode Target Source Files Introduction.

  1. The two targets in this example all use the Single View App template, so their source files are the same also.  Next, I will introduce them to you one by one.
  2. AppDelegate.swift: This is the entrance class when the iOS app starts, it contains methods that manage and respond to the iOS app life cycle event.
  3. ViewController.swift: This class is used to manage iOS app UI views and responses to UI events such as touch up etc.
  4. Main.storyboard: This is the iOS app UI designer file, it is an xml file. But with Xcode, you can edit it visually.
  5. Assets.xcassets: You save all app-related resource files under this folder, such as images. Just copy & paste resource files to save into it. Please refer article How To Add iOS App Icon, Image, Color Set To Xcode Project Assets Catalog Correctly.
  6. LaunchScreen.storyboard: Similar to Main.storyboard, but this file is used to design the screen UI when the app is launched.
  7. Info.list: Used to provide os with information property settings data about apps, bundles, or frameworks. For example, how should an application be started, how should it be localized, the name of the application, the icon to display.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.