In Xcode 3 it was easy to get an overview of which files are activated for current active target. I love the new feature in Xcode 4 where you can see all the targets a specific file is active for (its like an inversed view of xcode 3). Is there some mysterious way of getting that good ol' view back?
It would be really handy when specifying test-files and nibs for different targets...
Image from that good ol' list in xcode 3:
Expanding on tomwhipple's answer, there is a way to see all the files that are not part of a target.
Go to -> Build Phases -> Compile Sources and hit the '+' button. This will show you all the files that are not part of the target. However, this list is pretty cluttered with things that really shouldn't be in your target. But you can type ".m" in the search bar to only show the classes that aren't included.
By Target: Navigate to the project, then select the target and expand the various build phases. It's more specific because it shows you what role the file(s) play in the target.
By file: Select the file in the navigator and open the Utility pane. The targets list is shown there (but only for that one file).
I also find this lack of a checkmark list annoying. I did notice that you can add multiple files to a target via the + icon at the bottom of the compile sources list in the "by target" method.
Related
Is there any way that I can select some files only build selective files and make the build ignore some files in a project?
What compiler flags or Xcode options do I need to use?
In Xcode, show the project navigator (Cmd-1), click the file you want to remove from the current build. Show the file inspector (Cmd-Opt-1), locate "Target Membership" pane and uncheck the current target. Just check it to add it back.
You can do the same in the target "Compile Sources" phase but you'll need more clicks and if you have a few dozen files you'll need to search it in the list.
The fastest way to stop building temporarily a few lines that you know are wrong or incomplete is to wrap them with
#if 0
// code you want to skip
#endif
Also, if you want to run some experiments you can add a new target that includes those experimental files and add an scheme to build the experiment.
It would be much better if you use git and create an experimental branch, but that's a different story.
In the project settings, in Build Settings you can add and remove individual files. However, there is no way to only build some files and not others; you are building all the files in the project.
I added .png images to the Xcode project for conditional use like making screenshots of a view
However, since this is not needed for the Release version of the app, I would like to find a way to exclude them using some kind of settings for Target. I expect there can be a solution like using #if DEBUG macro for Debug compilation, which can work for lines of source code. But, in case of files included in project bundle, I am having trouble finding the answers.
In Xcode 3, there's a view above the editor that lists the files in the project. There's a checkbox on the right side of that view for each file, and you can uncheck the box to remove the file from the current target.
In Xcode 4, show the Project Navigator on the left side of the window, and show the File Inspector on the right side, in the Utilities area. When you select a file, you'll see a Target Membership area with a list of targets and checkboxes. If you want to exclude the file from a particular target, uncheck the box next to that target. Here's a picture:
This is a bit different from excluding files from only some builds of a single target. Still, I think it's the simplest mechanism to use for the situation that you describe. Simply duplicate your existing target so that you have a copy that you can use for making screenshots. Remove the extra files from your production target but leave them in the screenshot target, as described above.
A target's inputs are the same for all builds, so there's no checkbox that will do it for you.
All that really happens though is that image files like .png or whatever get added to the copy bundle resources phase. You can remove them from that phase and instead create a custom script build phase using a shell script.
It will default to printing out all the environment variables set by xcode, from there you should be able to write a script which only performs the copy when say ${BUILD_STYLE} is 'Debug'.
You probably want ${BUILD_STYLE}, ${CONTENTS_FOLDER_PATH} and ${INPUT_FILE_PATH} for starters.
Is there an easy way of getting Three20 v1.1 to work under xCode 4?
I followed the steps on http://three20.info/article/2011-03-10-Xcode4-Support but that seems to be for the master. I use v1.1 as I use the TTLauncher.
The project builds fine with a normal build, and runs perfect on an iPhone.
But when I want to create the archive (for the IPA for distribution) then I get 18 errors and 8 warnings.
The first one is:
../scripts/Protect.command: line 23: cd: /Users/XXX/Library/Developer/Xcode/DerivedData/iDoms-cmyivarwxpbvqdfnyclqdrikrtmw/ArchiveIntermediates/iDoms/BuildProductsPath/Release-iphoneos/../three20/Three20UICommon: No such file or directory
Most others are 'no such file or directory' on e.g.:
#import "Three20Core/TTGlobalCoreLocale.h"
or 'undeclared (first use of function)' which comes from the 'no such file or directory issue I presume'.
In my 'Header search paths' I have:
$(BUILT_PRODUCTS_DIR)/../three20
$(BUILT_PRODUCTS_DIR)/../../three20
../../three20/Build/Products/three20
/usr/include/libxml2
Any help would be very appreciated!
Just to add to Colin's answer: you can use Xcode's dependent projects feature to use three20, even though the three20 website says it's not "officially supported":
In your workspace, right-click on the empty space in your project navigator. Select "Add files to "My Workspace", and select the three20 project (three20/src/Three20/Three20.xcodeproj). This is the only project you need to add: it is not necessary to manually add the three20 subprojects.
Select your project in the navigator, go to Build Phases, open "Link binary with libraries", click on the "+" in the bottom left corner, and add the Three20 libraries: libThree20.a, libThree20Core.a, libThree20Network.a, libThree20Style.a, libThree20UI.a, libThree20UICommon.a and libThree20Navigator.a. This will cause Xcode to build Three20 when you build your project.
Add ${BUILD_DIR}/three20 to your include path as per Colin's answer: go to build settings, double click on "Header Search Paths", and add ${BUILD_DIR}/three20 (it will show as build/three20 when you close the dialog).
Add three20/src/Three20.bundle to your resources.
It's probably also a good idea to add the linker flags -ObjC and -all_load if you haven't already done so (same dialog, setting "Other Linker Flags").
The steps above are good enough for compiling the code. To make "Archive" work too, you will need to:
Add $(BUILT_PRODUCTS_DIR)/../three20 and $(BUILT_PRODUCTS_DIR)/../../three20 to the Header Search Paths setting. If you don't you will get compilation errors that the three20 headers cannot be found.
For all Three20 projects (so not just the top-level project), go the Build Settings and set "Skip Install" to YES. If you don't, the project will build, but you will not be able to create an IPA.
Make sure that your product name (select your target, go to Build Settings, then setting "Product Name") does not contain spaces, otherwise archiving will not work.
Finally, if you're getting errors such as ld: library not found for -lThree20 and you are using a custom build configuration (such as AdHoc), make sure to add the same build configuration to each of the Three20 projects too (just duplicate the Release configuration).
You should check out this StackOverflow question.
I've reproduced the accepted answer below:
So it looks like the easiest way
to get old Xcode 3.2 projects to work
with Xcode 4 is to do the following:
Go into Xcode 4's preferences (Cmd+,).
Select the "Locations" tab. Where it
says "Build Locations", select the
drop down and pick "Place build
products in locations specified by
targets" I'll write up a three20.info
article going into more details about
this.
Add these two paths to your header search paths in the build settings for your target:
"$(BUILD_DIR)/three20"
"$(BUILD_DIR)/../three20"
The first entry is needed for regular builds and the second entry is needed for archives.
It's that easy.
Incidentally, to create a file in your home directory with a list of all of Xcode's environment variables for your target's environement, add the following Run script build phase to your target with contents:
ENV > ~/xcode-environment.sh
Note that in this case, if your project is not making it through the compile phase of the build process, and your Run script comes later, the script won't get executed, so put it first.
Is there a place (or flag) in Xcode for files that you don't want to compile? There are some classes that are/may become part of a project but currently won't compile. The main project doesn't link to them but Xcode still tries to compile them. Is there a way to prevent blocking the rest of project from compiling until these new Classes are "ready"?
Note that for every source file you can specify which target(s) it belongs to - look at the inspector window for a file (Get Info) and then hit the Targets tab. If you deselect a target for a given source file then it won't be compiled as part of the build process for that target.
[This amounts to much the same thing as what Eimantas has said in his answer - it's just a different way of looking at it.]
Look for unneeded files in "Compile sources" in Target -> {AppName} branch. Remove them from there and they won't be compiled on next build (make sure to Clean before you Build again)
In Xcode 8.3.3, in the utilities window, click on File Inspector tab at the top of the window. Uncheck the file in the Target Membership area of the File Inspector. Please see image below.
You can use preprocessor statements:
#ifndef HIDE_<insert name here>
CODE
#endif
And then use:
#define HIDE_<insert name here>
above the aforementioned code in the files you don't want to compile.
I am developing an iPhone app and there will be a Full as well as a Lite version of that app. In order get both bundles from the same source code and Xcode project I added another target to the Xcode project.
Now, I want to have the Lite target copy only a subset of the resource files to the bundle. But, Xcode won't simply let me delete individual files from the "Copy Files to Bundle" build step, since I imported all my resources as folder references. I need this in order to maintain a directory structure in the resources directory.
How do I solve this problem? Any suggestions or ideas are greatly appreciated!
In the left-hand panel of Xcode, right-click on the "Groups & Files" bar at the top. Check "Target Membership".
Now you'll see a tick against every file that should be included in your current build target. Untick the ones you don't want, switch to your other target, and repeat.
Instead of manipulating the "Copy Bundle Resources" step of your target, you can right-click resource files or groups (folders), choose "Get Info," and selectively leave stuff out of your Lite build under the Targets tabs of the info window for the file(s) you selected. Doing this on a group (folder) recurses the changes, so using resource groups (folders) is a nice easy way to make separate resources collections for separate builds.