Xcode: Project and Target, add resources to target? - xcode

I'm building my first app and I'm a bit confused about all the project and target settings. So far I understand that a project can have multiple targets, for example a lite and a full version. So first I'm building my full version and later on adjusting it for the lite one.
My question is now about the resources you add to the targets. So far I've never checked the checkbox "Add to target …" while adding images, fonts etc. Still it works fine. So why or why shouldn't I check this box? And if I need to check it, how can I do this for all the images etc. I've added to the project?
And I think in my resource folder are still some resources I don't need anymore and actually deleted in Xcode (correctly, not just deleting the link basically)..how can I get rid of them?

When you add a file/resource in Xcode (either using "New File" or "Add File to "), you will see a checkbox for all the targets in your project. You can check the ones that you want to include the new file/resource. For the existing file/resources in xcode, you have following two options:
For your target->Build Phases->Copy Bundle Resources, you can add resources to the target.
Click on the file/resource in project navigator, under "Utility View"->Target Membership, you can select/deselect the targets that need to include/remove this file/resource.
Regarding deleting resources, when you delete a resource or any file in XCode, it will give you options: "Remove Reference" or "Move to Trash". For both of these options, resource will be removed from all the targets and XCode project file. However, if you choose "Move to Trash" it will also be removed from the folder in your hard disk.

Related

How to add json file to Xcode project [duplicate]

I'm trying to add some new resource files to a project which was build by another person on another mac. I think that the project has the provision of the previous person.
Using right click->Add Files to "MyProject" doesn't provide the expected result. After I compile the project, the added file is not visible in the application.
How can I add new resources in my project?
PS: I'm trying to learn Objective-C in a macincloud.com account.
It might be that the file you added was not added to the project build. Click your project > App target > Build Phases
And check that the file exists in Compile sources (if it needs to be compiled), otherwise check Copy bundle resources. If the file does not exist there, drag it there and it should be fine, (from what I understand of your question).
EDIT
You can also check wether a file is added to the target by clicking the file and opening the "File Inspector" (View > Utilities > Show File Inspector, or ⌥ + ⌘ + 1), and check the Target Membership section.
Example:
Adding to Copy bundle resources worked for me
Just drag the resource file (from a finder window) into your project files area (left side) and drop in supporting files.
Once you drop, a dialog will prompt you which targets to add it for. Select all that are appropriate. Thats it.
Just had a similar experience with Xcode Version 11.7 (11E801a), which I mention as it may help others from wasting a day and a half.
In addition to the other answers explaining how to add the resources:
For me the problem was I had my resources listed in Developer Assets under the target's General tab, but also in the Build Phases/Copy Bundle Resources. This worked fine running through Xcode in simulators and even on devices, but when I came to Archive the app, the resources were not being copied. Deleting my resources from the Developer Assets list, but keeping them in Build Phases worked.
And in the end it turns out I only need the resources in the Build Phases section for either running through XCode or Archiving !

XCode 5.1 crashes when I drag-drop one project into another project's tree

I've created a new "single view" iOS universal app.
I want to link theamazingaudioengine
I'm on step 2 here: http://theamazingaudioengine.com/doc/_getting-_started.html
"Drag TheAmazingAudioEngine.xcodeproj from that folder into your
project's navigation tree in Xcode. It'll be added as a sub-project."
But instead, I'm trying to place it alongside:
To my mind it makes more sense that the project should be next to each other.
However, I can't include the .a as a target dependency. I can't drag drop it. And if I click the +, there is no possibility to include it.
So maybe I am wrong, and I have to do exactly as the instruction says?
So I try to drag-drop "TheAmazingAudioEngine" into the Ultra project-tree, between "Ultra" project and "Ultra" folder.
This crashes Xcode.
It is repeatable.
Should I file a bug, and am I wrong to to place the projects side-by-side?
It crashes for me too if I drag and drop.
Found that by using the Add files to "my project" setting it will work.
When you choose the Add files option, navigate and ONLY add the theamazingaudioengine.xcodeproj file. It will automatically add the whole project. Now you will be able to link.
This issue has been fixed in Version 5.1.1. The update was released on April 10.
https://itunes.apple.com/us/app/xcode/id497799835?mt=12

Adding resource files to xcode

I'm trying to add some new resource files to a project which was build by another person on another mac. I think that the project has the provision of the previous person.
Using right click->Add Files to "MyProject" doesn't provide the expected result. After I compile the project, the added file is not visible in the application.
How can I add new resources in my project?
PS: I'm trying to learn Objective-C in a macincloud.com account.
It might be that the file you added was not added to the project build. Click your project > App target > Build Phases
And check that the file exists in Compile sources (if it needs to be compiled), otherwise check Copy bundle resources. If the file does not exist there, drag it there and it should be fine, (from what I understand of your question).
EDIT
You can also check wether a file is added to the target by clicking the file and opening the "File Inspector" (View > Utilities > Show File Inspector, or ⌥ + ⌘ + 1), and check the Target Membership section.
Example:
Adding to Copy bundle resources worked for me
Just drag the resource file (from a finder window) into your project files area (left side) and drop in supporting files.
Once you drop, a dialog will prompt you which targets to add it for. Select all that are appropriate. Thats it.
Just had a similar experience with Xcode Version 11.7 (11E801a), which I mention as it may help others from wasting a day and a half.
In addition to the other answers explaining how to add the resources:
For me the problem was I had my resources listed in Developer Assets under the target's General tab, but also in the Build Phases/Copy Bundle Resources. This worked fine running through Xcode in simulators and even on devices, but when I came to Archive the app, the resources were not being copied. Deleting my resources from the Developer Assets list, but keeping them in Build Phases worked.
And in the end it turns out I only need the resources in the Build Phases section for either running through XCode or Archiving !

Three20 v1.1 and Xcode 4

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.

Xcode Different Resources For Different Targets

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.

Resources