I have a series of targets, and each one looks at a global variable I am currently storing in a constants file for the name of the directory in which that app's resources live. However, this means that I have to change this value each time i change the target, which is a terrible process.
What is the best way to change that value in each target? Or should i specify this value somewhere in my target plist ? If so how do i retrieve that value?
Thanks!
Go to project's settings in the Project Navigator panel. Under the Targets sections, right click the existing target and select Duplicate to copy your existing target. 2. Xcode will ask you if your new target is for iPad development.
Build Settings The dropdown menu of the Deployment Info section is nothing more than a convenient way to define a build setting. Select the Build Settings tab at the top and search for deployment target. The Deployment section shows four build settings that relate to the deployment target: iOS Deployment Target.
There's another and efficient way to create and store global variable is using a struct, you should always create a struct and encapsulate all the global variable inside it and can use in any class wherever we want., Let's see how we can do it. This is how we can create global variables in swift.
A Target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute.
With your project open in Xcode, look in the Groups & Files panel for your Target. Right click to bring up your popup menu. Select Get Info. Select the build tab. Scroll down to the "Preprocessor Macros" and add something like "MY_OPTION_1". Do something similar for your other targets. Say "MY_OPTION_2", "MY_OPTION_3", etc.
Now, in your code you can do a define test. Like
#ifdef MY_OPTION_1
// define values here
#endif
#ifdef MY_OPTION_2
// define values here
#endif
#ifdef MY_OPTION_3
// define values here
#endif
Then, depending on what target you use, the values within the corresponding defines are used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With