Adding a build variant and running it on iOS 8 - ios

When you create a new iOS project you have 2 build variants, Debug and Release (or at least that's what they are called in Android, Build Variant).
Is it possible to create a another build variant? Let's say, "Staging".
Then, how do I run my app on a different build variant, for example how do I run it in release mode on the emulator/development device?

Yes, here's how.
To add a build configuration
In the menu to the left, select your project.
To the right, you'll see "PROJECT" and "TARGETS". Select your project.
Go to the Info tab and click '+' under Configurations and choose "Duplicate "Debug"/"Release" configuration" and name it whatever you'd like.
To choose which build type to use
Click "NameOfMyProject" next to the device you're building to (upper left of the screen) and choose "Edit scheme".
Choose Run -> Build Configuration -> NameOfYourBuildConfiguration.
Hope it helps.

Related

XCode 6: The custom class and the several project targets

I would like to have both DEV & PROD versions of my app working on my iPhone at the same time.
So I created a new target AppNameDev with a different bundle identifier.
When I launch the app on my iPhone, I get the error :
Unknown class _TtC4Wesh10InviteCell in Interface Builder file.
My custom class InviteCell is not found by the new target's interface builder. How to tell it where to find the class ?
When you click the InviteCell source file check from the File Inspector on right that both targets are checked. Or that the file exists in Build Phases - Compile Sources for both targets.
You need to click "InviteCell" class file from left side on Project Navigator and then go to "File Inspector" and click both targets (DEV & PROD) from Target Membership on the right side. I hope that helps you. For example:
Pro Tip: If you are planning to create a new file, make sure to select both DEV & PROD version targets before you click to "create" button. It will save you a lot of time because you don't have to go back and forth.

Xcode test target with host application forces wrong target into build section of scheme

When I add a test target that needs a host application in order to run Xcode adds targets that are not associated with the application I added.
I have two schemes (internal & production). I want to run tests on our internal application. When I add the internal application as a host I end up with the production target being added to builds and cannot delete it. If I remove the host application this goes away but the tests also fail.
Does anyone know where I'm going wrong?
We had the same problems, we fixed them with these steps:
in your testing target, go to the tab 'General' and set the hosting application to 'none', then go to 'Build phases' and remove the target dependency on the former hosting target.
(don't know if this step is necessary) go to 'Window'->'Projects', remove Derived Data from the hosting target and close Xcode. Reopen Xcode again, open your project/workspace.
edit your hosting target's scheme, select "Build" on the left and uncheck "Find Implicit Dependencies" - I believe that this function is somewhat buggy.
in your testing target, go to the tab 'General' and set the hosting application back to its previous value, recheck the target depdencies.

How to share files between two xcode projects in workspace?

I learnt about Xcode workspace .I know how to share the static library but i want to share the files between two xcode projects in workspace and is it possible to run multiple targets at a time?Can you provide me the information of how to do this.
Thanks in advance
Sharing files between projects in the same workspace is easy, even if the projects are on the same level (no subprojects):
Assume you want to share constants between Project1 and Project2, and these constants are defined in a file SharedConstants.swift, which is defined in Project1.
In order to be used in Project2, it must be compiled there.
Thus, activate in the project navigator Project2, select the target and open the Build Phases tab.
Open there Compile Sources by tapping the little triangle left.
Tap the + button below the listed sources for this target. This will show you a list of files of Project2. There you cannot select your shared constants, because they do not belong to this project.
However left bottom is a button Add other…
Tapping it will open a standard file selection window where you can select SharedConstants.swift from Project1.
After tapping Open, a 2nd window opens with a Destination: Copy items if needed checkbox.
Important: Do not check this box!
If you would check it, a copy of SharedConstants.swift would be used in Project2, and any changes that you make in Project1 would not be visible in Project2. Instead, it you uncheck it, only a reference to SharedConstants.swift in Project1 would be used in Project2, and any changes will affect both projects.
To share the files you can probably use the bundles
Targets are manipulated with Schemes in Xcode 4, you can launch several targets in the same time if you select the different destinations (with OS X you can probably have the same destination :) )
You'll see a little triangle below the stop button indicating that you can long-press it to select which operation should be terminated:
You can switch the console with the popover at the Debug area where you see the target name and icon - that's a button.
You can drag Xcode projects into other Xcode projects to nest them.
More info here:
How should I manage dependencies across projects in an Xcode workspace?

How to find out if a build is debug or release

Is there a compile time variable that lets me detect whether the current build is for debug or release? If not, how can I define my own?
As of Xcode 4, the Build, Run, Test, and Analyze actions produce Debug builds by default; the Profile and Archive actions produce Release builds. This is controlled by editing the scheme, selecting the action, then changing the build configuration under the Info tab. To Apple in Xcode 4, the Archive action is the final "build this for release so I can distribute it" action. This is the highest level at which you manage these settings.
At the lower level, your target contains its build settings, which define configurations. By default, there are two configurations: Debug and Release. You can find (and manage) them by selecting the project (the root node) in the Project navigator, then choosing the Info tab. They're found under the Configurations group.
To edit the settings for the various configurations for a given target, choose the target in the Targets list, then choose the Build Settings tab. The grid looks (and sort of is) complicated and you should read the docs for details (esp. the what the different columns represent). To answer your question, each setting can be edited to change the setting for all configurations or expanded with the disclosure triangle so you can specify configuration-dependent settings. For example: under Release configuration, you might want to strip debugging symbols; under Debug, you do not.

Where is set the active build configuration in Xcode 4

I have 3 configurations in my project (Debug, Distribution_AdHoc and Distribution_AppStore). In Xcode 3 we had a list to choose device, version, configuration and target before build and run. Now with Xcode 4 we only have the device kind and version in this list. This bring my two questions:
So where is defined the configuration used ? Is that the configuration defined in "Project > Info > Command-line builds use: Debug" ?
And now the "Project" menu is replaced by "Product" So where can we create (or duplicate and edit) a Configuration ?
Thank you.
Just in case you still want to make a Distribution config (or other config--I still find them useful), after great length (read: searched in the help for 'duplicate'), I found this:
At first, they were all grayed out; this was because I had one of the targets highlighted in the editor (MFE, MFETests, etc.). If you highlight your project (as in the screenshot), they become enabled.
You can use alt(option) and click on either, run, test or profile to see the option.
Here you can set the target for each option.
For Archive the release is normally used, since can you resign your app via the organizer there is no need ad-hoc and appstore target any more.
For part 1 of your question,
The configuration is set in the schema window. apple+shift+comma to get to the window. Or Product > Scheme > Manage Schemes from the menu bar.
In the window, click the type of build you want on the left panel: Build, Run, Profile, Analyze, or Archive. In the window tab usually, along the type, there is an option Build Configuration that can be set. Select Debug, Release, or whichever configuration you want there.
The exception if the build task. The build task uses whatever configuration is set for the Run task. Also, the analyze and archive tasks only have one tab, so using the info tab is not necessity.
Apparently, "build" is shorthand for "build for run"...

Resources