iOS Xcode Project And Target Structure Example

After you create a 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 target ( a target is something like a child project ). This article will introduce all those you care. 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 sub folder in the project navigator, the sub folder name is same as the project name.
  2. If you click the project name in left navigator panel, you can see the sub project also under the Target item in the right panel. You can think Target as a sub project. Below picture contains two Target child project, because i just create another target which name is Target1.
    ios xcode project target panel
  3. If you click the the project HelloWorldSwift in the right panel, you can see the project information as below. You can change settings information such as Deployment Target etc.
    ios xcode project information panel
  4. If you click the sub project under the TARGETS item, it will display the target related settings in the right panel, you can also change settings under Deployment Info section such as choose different devices 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.

Now you should have understood what the difference between Xcode project and target. Next i will tell you how to create target in Xcode.

  1. Click File —> New —> Target in the Xcode top menu bar.
    ios create target in xcode file new target
  2. Select iOS —> Single View App in the popup template dialog.
    xcode ios single view app template
  3. In the next dialog, input product name Target1, and select project HelloWorldSwift, the language should select Swift.
  4. When the process finished, you can see both HelloWorldSwift and Target1 under the project. They has the same source files because of using same template.
  5. When you run the project, you can select which target to run at the top Manage Schemas drop down list as below.
    ios xcode run different target drop down list
  6. Also the two targets can be found under the Products folder in left project navigator. So each target is a product in Xcode.
READ :   iOS Application Life Cycle Example

3. Xcode Target Source Files Introduction.

The two target in this example all use Single View App template, so their source files are same also.  Next i will introduce them to you one by one.

  1. AppDelegate.swift : This is the entrance class when iOS app start, it contains methods that manage and response to the iOS app life cycle.
  2. ViewController.swift : This class is used to manage iOS app UI views and response to UI events such as touch up etc.
  3. Main.storyboard : This is the iOS app UI designer file, it is an xml file. But with Xcode, you can edit it visually.
  4. Assets.xcassets : You save all app related resource files under this folder, such as images. Just copy & paste resource files to save into it.
  5. LaunchScreen.storyboard : Similar to Main.storyboard, but this file is used to design the screen UI when app is launched.
  6. Info.plist : Used to provide iOS with important information 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 Reply

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.