Thursday, April 18, 2024
HomeiOS DevelopmentAdd a number of targets to swift mission – iOSTutorialJunction

Add a number of targets to swift mission – iOSTutorialJunction

Including a number of targets to swift mission is a necessity of hour. For instance, in case your app level to completely different finish factors. One finish level is pointing to improvement server and second endpoint is for manufacturing or dwell server, then most typical strategy for a newbie iOS developer is to remark out completely different finish factors whereas producing builds for particular surroundings. Creating particular person targets for various configurations saves iOS builders from this headache of commenting and uncommenting code for various configurations/settings.

Why we have to add a number of targets in swift

  • If our app is utilizing completely different servers finish factors
  • Single app goes for use for various customers(instance buyer consumer and admin consumer)
  • Must made two app model (Free and Paid)

Steps so as to add a number of targets in swift

1. Create a reproduction goal as proven in picture

Create a duplicate target

2.Rename this duplicate goal. We renamed it to Manufacturing. Similar change title of information.plist file created by xcode for our manufacturing goal.

Changing info.plist name for our new target

3.Point out similar title in construct setting of Manufacturing goal.

Changing plist name in build setting of our new target

4. Add swift flag for our targets as proven in beneath picture. Flags are required so as to place checks programmatically. Do these steps for all targets and simply change identifier. On this picture we used “Dev”. For Manufacturing goal we are going to use “Prod”.

Steps to add macro for target

5. Go to energetic schemes, subsequent to play and cease button. Attempt to choose a scheme and click on on new scheme. A pop up will seem. Choose Manufacturing goal and title scheme as similar title i.e. Manufacturing.

Adding new scheme for new target

Programmatically including checks for various targets

Open ViewController.swift and add beneath code

        #if Dev
         print("We're utilizing dev model")
         print("We're utilizing manufacturing goal")

Right here we use the flags set by us in construct setting of the goal. For default goal we set flag as “-D Dev”. Thus right here compiler will test for swift flags for targets. When you have greater than two targets then you possibly can as

        #if Dev
         print("We're utilizing dev model")
        #elseif Staging
         print("We're utilizing staging model")
         print("We're utilizing manufacturing goal")

The place to go from right here

On this publish, we realized that how we will add a number of targets to swift mission. By including a number of targets developer cab be relieved from ache of commenting uncommenting codes associated to completely different app variations.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments