Multiple release configurations in Xcode - objective-c

I'm trying to build two separate applications for release. One of them should have less features than the other. I would disable those features with macros. Something in the lines of:
#ifdef DEMO_VERSION
// less code
#else
// more code
#endif
The question is, how do i define the DEMO_VERSION (which i would usually just put under "other preprocessor macros") so that i could easily switch it on and off? I could just define it manually every time i need to compile the app and delete it when compiling the actual release version, but i suspect there could be a smarter way of achieving this.

You can manage build configurations from the project info view in Xcode. Here, you can duplicate the default "Release" configuration, and then adjust the build settings to define a specific preprocessor macro for each configuration:
Select your project from the project navigator pane on the left. In the projects/targets list that is shown, ensure you have the project selected.
Choose the Info tab. Under Configurations, click + > Duplicate "Release" Configuration and rename it something like "Release (Demo)".
Choose the Build Settings tab. Expand the Preprocessor Macros entry to show the per-configuration settings. Add DEMO_VERSION=1 for the "Release (Demo)" configuration only.
Now, at compile time, your preprocessor statements will conditionally compile based on your current build configuration.

Related

iOS save an Object in the keychain [duplicate]

I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing that there was a way to disable ARC on a per-file basis, though I have been unable to find this option.
Is this possible? How do I disable ARC on a per-file basis?
It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files.
You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box. (Note that editing multiple files will overwrite any flags that it may already have.)
I created a sample project that has an example: https://github.com/jaminguy/NoArc
See this answer for more info:
Disable Automatic Reference Counting for Some Files
Disable ARC on MULTIPLE files:
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fno-objc-arc
Press Enter or Done
;)
For Xcode 4.3 the easier way might be: Edit/Refactor/Convert to objective-C ARC, then check off the files you don't want to be converted. I find this way the same as using the compiler flag above.
It is very simple way to make individual file non-arc.
Follow below steps :
Disable ARC on individual file:
Select desired files at Target/Build Phases/Compile Sources in Xcode
Select .m file which you want make it NON-ARC
PRESS ENTER
Type -fno-objc-arc
Non ARC file to ARC project flag : -fno-objc-arc
ARC file to non ARC project flag : -fobjc-arc
Note: if you want to disable ARC for many files, you have to:
open "Build phases" -> "Compile sources"
select files with "left_mouse" + "cmd" (for separated files) or + "shift"
(for grouped files - select first and last)
press "enter"
paste -fno-objc-arc
press "enter" again
profit!
Just use the -fno-objc-arc flag in Build Phases>Compile Sources
Select Xcode project
Go to targets
Select the Build phases section
Inside the build phases section select the compile sources.
Select the file which you do not want to disable ARC and add -fno-objc-arc
It is possible to disable ARC (Automatic Reference Counting) for particular file in Xcode.
Select Target -> Build Phases -> Compile Sources -> Select File (double click) -> Add "-fno-objc-arc" to pop-up window.
I had encountered this situation in using "Reachibility" files.
This is shown in below figure :
use -fno-objc-arc for each file in build phases
The four Mandatory Step as explained in this video
//1. Select desired files
//2. Target/Build Phases/Compile Sources
//3. Type -fno-objc-arc
//4. Done
Please Just follow the screenshot and enter -fno-objc-arc .
If you're using Unity, you don't need to change this in Xcode, you can apply a compile flag in the metadata for the specific file(s), right inside Unity. Just select them in the Project panel, and apply from the Inspector panel. This is essential if you plan on using Cloud Build.
I think all the other answers are explaining how to disable MRC(Manual Reference Count) and enabling ARC(Automatic Reference Count).
To Use MRC(Manual Reference Count) i.e. Disabling ARC(Automatic Reference Count) on MULTIPLE files:
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fobjc-arc
Press Enter or Done
Add flag “-fno-objc-arc”.
Simple follow steps :
App>Targets>Build Phases>Compile Sources> add flag after class “-fno-objc-arc”
Just use the -fno-objc-arc flag in Build Phases>Compile Sources infront of files to whom you dont want ARC to be apply.
GO to App -> then Targets -> Build Phases -> Compile Source
Now, Select the file in which you want to disable ARC
paste this snippet "-fno-objc-arc" After pasting press ENTER
in each file where you want to disable ARC.
select project -> targets -> build phases -> compiler sources
select file -> compiler flags
add -fno-objc-arc
Following Step to to enable disable ARC
Select Xcode project
Go to targets
Select the Build phases section
Inside the build phases section select the compile sources.
Select the file which you do not want to disable ARC and add -fno-objc-arc

How to set target settings for different builds

In xcode 4.5 how do I select different target settings for different builds for example one target setting for debug, one target setting for release etc, so I can define different icons depending on the build etc.
You have two options, neither perfect. I'm going to focus on the concrete example of using different icons depending on your build configuration, as you suggest, though both techniques can be applied more broadly.
Redirect in your Info.plist
This is the simplest way. Specify your "Icon file" property in your target's Info.plist as e.g. "Icon-${CONFIGURATION}". Then, create two ICNS icons, "Icon-Release.icns" and "Icon-Debug.icns", and add them to your project. That's it. The downside with this approach is that both icons will be copied into your built app every time, rather than just the one it needs.
Use a "Run Script" build phase
This is a little more involved but it gives you a better result. Add a Run Script build phase to your target, with the following script:
cp "$(dirname "${PRODUCT_SETTINGS_PATH}")/Icon-${CONFIGURATION}.icns" "${SCRIPT_OUTPUT_FILE_0}"
Specify its output file as:
$(TARGET_BUILD_DIR)/$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/Icon.icns
And make sure your "Icon file" property in your Info.plist is set to just "Icon".
This relies on your icons sitting in the same folder as your Info.plist within your source tree (though you can edit the script however you like to suit your project's configuration).
Note also that with this approach Xcode won't be able to see that you have the icon set correctly, so for example in the "Summary" tab of your target's settings it'll still show the question mark placeholder for the icon. You'll need to do an actual build to verify it's working.
My solution is pretty close from Wade's first point, you can also add an dynamic suffix using a user-defined settings in you project configuration.
I use this solution to dynamize the icon, the bundle display name and also the bundle identifier of my build to be able to use the version from the app store beside my development version.

How to create conditional build in Xcode Project? Either using Macro or setting global bool variable

Xcode Project: How to create conditional build via Xcode Project
I had tried to define preprocessed macro such as LIGHTER_VERSION_APP at target or project level setting. Now I'm trying to use this macro in the other dependent project of my main project. I'm not able to use this LIGHTER_VERSION_APP macro in other dependent project.
Can anybody tell me how I can do that?
Thanks
In your Xcode project or target settings, under the compiler settings, you can add any flags you like to "Other C Flags" and "Other C++ Flags". You can simply add "-D LIGHTER_VERSION_APP" and it should now be defined when compiling your project. Once that's done, you can use #if defined LIGHTER_VERSION_APP in your code to turn stuff on or off.

Using code that doesn't support ARC, from an ARC project [duplicate]

I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing that there was a way to disable ARC on a per-file basis, though I have been unable to find this option.
Is this possible? How do I disable ARC on a per-file basis?
It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files.
You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box. (Note that editing multiple files will overwrite any flags that it may already have.)
I created a sample project that has an example: https://github.com/jaminguy/NoArc
See this answer for more info:
Disable Automatic Reference Counting for Some Files
Disable ARC on MULTIPLE files:
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fno-objc-arc
Press Enter or Done
;)
For Xcode 4.3 the easier way might be: Edit/Refactor/Convert to objective-C ARC, then check off the files you don't want to be converted. I find this way the same as using the compiler flag above.
It is very simple way to make individual file non-arc.
Follow below steps :
Disable ARC on individual file:
Select desired files at Target/Build Phases/Compile Sources in Xcode
Select .m file which you want make it NON-ARC
PRESS ENTER
Type -fno-objc-arc
Non ARC file to ARC project flag : -fno-objc-arc
ARC file to non ARC project flag : -fobjc-arc
Note: if you want to disable ARC for many files, you have to:
open "Build phases" -> "Compile sources"
select files with "left_mouse" + "cmd" (for separated files) or + "shift"
(for grouped files - select first and last)
press "enter"
paste -fno-objc-arc
press "enter" again
profit!
Just use the -fno-objc-arc flag in Build Phases>Compile Sources
Select Xcode project
Go to targets
Select the Build phases section
Inside the build phases section select the compile sources.
Select the file which you do not want to disable ARC and add -fno-objc-arc
It is possible to disable ARC (Automatic Reference Counting) for particular file in Xcode.
Select Target -> Build Phases -> Compile Sources -> Select File (double click) -> Add "-fno-objc-arc" to pop-up window.
I had encountered this situation in using "Reachibility" files.
This is shown in below figure :
use -fno-objc-arc for each file in build phases
The four Mandatory Step as explained in this video
//1. Select desired files
//2. Target/Build Phases/Compile Sources
//3. Type -fno-objc-arc
//4. Done
Please Just follow the screenshot and enter -fno-objc-arc .
If you're using Unity, you don't need to change this in Xcode, you can apply a compile flag in the metadata for the specific file(s), right inside Unity. Just select them in the Project panel, and apply from the Inspector panel. This is essential if you plan on using Cloud Build.
I think all the other answers are explaining how to disable MRC(Manual Reference Count) and enabling ARC(Automatic Reference Count).
To Use MRC(Manual Reference Count) i.e. Disabling ARC(Automatic Reference Count) on MULTIPLE files:
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fobjc-arc
Press Enter or Done
Add flag “-fno-objc-arc”.
Simple follow steps :
App>Targets>Build Phases>Compile Sources> add flag after class “-fno-objc-arc”
Just use the -fno-objc-arc flag in Build Phases>Compile Sources infront of files to whom you dont want ARC to be apply.
GO to App -> then Targets -> Build Phases -> Compile Source
Now, Select the file in which you want to disable ARC
paste this snippet "-fno-objc-arc" After pasting press ENTER
in each file where you want to disable ARC.
select project -> targets -> build phases -> compiler sources
select file -> compiler flags
add -fno-objc-arc
Following Step to to enable disable ARC
Select Xcode project
Go to targets
Select the Build phases section
Inside the build phases section select the compile sources.
Select the file which you do not want to disable ARC and add -fno-objc-arc

How can I disable ARC for a single file in a project?

I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing that there was a way to disable ARC on a per-file basis, though I have been unable to find this option.
Is this possible? How do I disable ARC on a per-file basis?
It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files.
You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box. (Note that editing multiple files will overwrite any flags that it may already have.)
I created a sample project that has an example: https://github.com/jaminguy/NoArc
See this answer for more info:
Disable Automatic Reference Counting for Some Files
Disable ARC on MULTIPLE files:
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fno-objc-arc
Press Enter or Done
;)
For Xcode 4.3 the easier way might be: Edit/Refactor/Convert to objective-C ARC, then check off the files you don't want to be converted. I find this way the same as using the compiler flag above.
It is very simple way to make individual file non-arc.
Follow below steps :
Disable ARC on individual file:
Select desired files at Target/Build Phases/Compile Sources in Xcode
Select .m file which you want make it NON-ARC
PRESS ENTER
Type -fno-objc-arc
Non ARC file to ARC project flag : -fno-objc-arc
ARC file to non ARC project flag : -fobjc-arc
Note: if you want to disable ARC for many files, you have to:
open "Build phases" -> "Compile sources"
select files with "left_mouse" + "cmd" (for separated files) or + "shift"
(for grouped files - select first and last)
press "enter"
paste -fno-objc-arc
press "enter" again
profit!
Just use the -fno-objc-arc flag in Build Phases>Compile Sources
Select Xcode project
Go to targets
Select the Build phases section
Inside the build phases section select the compile sources.
Select the file which you do not want to disable ARC and add -fno-objc-arc
It is possible to disable ARC (Automatic Reference Counting) for particular file in Xcode.
Select Target -> Build Phases -> Compile Sources -> Select File (double click) -> Add "-fno-objc-arc" to pop-up window.
I had encountered this situation in using "Reachibility" files.
This is shown in below figure :
use -fno-objc-arc for each file in build phases
The four Mandatory Step as explained in this video
//1. Select desired files
//2. Target/Build Phases/Compile Sources
//3. Type -fno-objc-arc
//4. Done
Please Just follow the screenshot and enter -fno-objc-arc .
If you're using Unity, you don't need to change this in Xcode, you can apply a compile flag in the metadata for the specific file(s), right inside Unity. Just select them in the Project panel, and apply from the Inspector panel. This is essential if you plan on using Cloud Build.
I think all the other answers are explaining how to disable MRC(Manual Reference Count) and enabling ARC(Automatic Reference Count).
To Use MRC(Manual Reference Count) i.e. Disabling ARC(Automatic Reference Count) on MULTIPLE files:
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fobjc-arc
Press Enter or Done
Add flag “-fno-objc-arc”.
Simple follow steps :
App>Targets>Build Phases>Compile Sources> add flag after class “-fno-objc-arc”
Just use the -fno-objc-arc flag in Build Phases>Compile Sources infront of files to whom you dont want ARC to be apply.
GO to App -> then Targets -> Build Phases -> Compile Source
Now, Select the file in which you want to disable ARC
paste this snippet "-fno-objc-arc" After pasting press ENTER
in each file where you want to disable ARC.
select project -> targets -> build phases -> compiler sources
select file -> compiler flags
add -fno-objc-arc
Following Step to to enable disable ARC
Select Xcode project
Go to targets
Select the Build phases section
Inside the build phases section select the compile sources.
Select the file which you do not want to disable ARC and add -fno-objc-arc