How to get Xcode to refresh folder references on device? - xcode

I created a folder reference by doing the following:
Created a folder on disk. Added whatever files are meant to be in it.
In Xcode
---> Add files to project
---> Clicked on folder
---> Unchecked copy files if necessary
--->Clicked create folder references for any added folders
The problem:
Whenever I make changes to files in the folder (add/delete) etc. The changes are picked up in Xcode. (You can see the changes in project navigator). These changes are not there when I run on the simulator. Deleting the application on the simulator does not help. Only when I click "Reset content and Settings" in the simulator, does it pick up the changes.
I already have added the following script to my build phases:
touch -cm "${BACKGROUND_TEXTURES}"
It is run after compiling, but before copying bundle resources. My bundle resources contain this folder.
I'm not sure whether the script matters, since Xcode picks up the changes with to without it. It's the simulator that doesn't get updated, unless I manually set "Reset content and settings".
What is the correct way to solve my problem?
EDIT: I have tried Clean, then Build, but that doesn't seem to make any difference.

Example:
I create "Images" folder at project folder, and I "create folder references for any added folders".
Next I add touch -cm ${SRCROOT}/../../Images to Run Script,And I drag "Run Script" before to "Compile Sources"
clean and build,it's ok.

Related

Xcode add reference to files instead of copy

I have created my framework that i want to add in my project. What i do is:
In my project i chose Xcode -> File -> Add Files to..
In prompt window i go for framework directory, chose .xcodeproj file
Check "Copy items if needed" and "Added folders - Create groups" radio button
What i expect - .xcodeproj that contain my framework is added and copied to my project
What i got - i can see file in Xcode, but not in folder when my app exist. So, when i try to Delete -> Move to trash my framework, it delete it in folder when it was created (not my project folder).
I can't figure out how to actually add and copy file instead of reference to it.

How to configure Xcode to place build products inside project folder?

In Xcode (6.3), you can change the default build location in Preferences ▸ Locations ▸ Derived Data ▸ Advanced.
I've now set it to "Custom" and "Relative to Workspace" so it would always be located relatively to the location of the project folder, and specified the build folder as Build.
However, the Build folder appears in the same directory as the .xcodeproj folder. How can I make it go inside it instead?

How can I include a txt file in an Xcode project?

I added a file "IntegerArray.txt" as follows, first I went to File -> Add file to "project name", I selected my file and it was copied into the root folder of my project, the same one that contains the .xcodeproj file. Then I clicked on my project's .xcodeproj file in Xcode, after which I went to Build Phases -> Copy Files -> "IntegerArray.txt", however when I build my project, the following code doesn't work
let bundle = NSBundle.mainBundle()
let path = bundle.pathForResource("IntegerArray", ofType: "txt")
println(path)
I expect to see the path to the file as output, but instead I see nil.
So I want to copy a file to my project in such a way that the above code works. How can I do this?
If I have a normal Cocoa Application, then when I add files they are automatically copied to the built program's bundle. However, with Command Line Tool's this doesn't seem to be the case, I'm starting to suspect a bug with Xcode.
If you don't have a Resources directory in your project, select your project:
Then from the File Menu select Add Files:
In the window that opens click on the "New Folder" button in the lower left hand corner of the window.
A small pop-up window will open; type Resources in that window for the folder name then click the "Create" button. You should now have a Resources folder in your project.
Then the way I do it is to use Finder to copy the file into the Resources Directory of my project.
After the file is in the Resources Directory (in Finder), back in Xcode select the Resources directory in your project:
and use the File-> Add Files menu selection again. You should see your file highlighted (affineOutput.txt in this case):
Double Click on it and it will become part of the bundle.
As Milliways says, then check the Build Phases in your project to be sure the file is in the Copy Bundle Resources. If it's somewhere else, just drag it into the Copy Bundle Resources.
If you include in the Resources Folder it should be included.
You may need to select the Project and Target.
In Build Phases check is there is entry under Copy Bundle Resources

Xcode - duplicate Target - new Target fails to build

using Xcode 3.2.5 on 10.6.6 (10J521) and now 10J537.
I have an Xcode project containing 1 Target: "MyApp". It builds and runs successfully.
As well as source and resource files, the Target contains a "Copy Files" build phase which copies "Sparkle.framework" in. The framework is in the same directory as the project.
I want to duplicate this Target. Steps taken:
Did "Clean all Targets".
Right-clicked on the "MyApp" Target within Xcode, and then chose "Duplicate".
Renamed the duplicated target to "MyAppTarget2".
Selected "MyAppTarget2" as the Active Target from the popup menu in the top-left.
Did "Build".
The problem:
error: Sparkle/Sparkle.h: No such file or directory
At the line:
#import <Sparkle/Sparkle.h> // In MyAppDelegate.mm
This is puzzling! Further info:
Each Build step appears to have been replicated in the duplicated Target, including the "Copy Files" phase.
The Sparkle.framework itself exists in the project's folder.
In the "Link Binaries with Library" phase of both "MyApp" and "MyAppTarget2", I am linking to the Sparkle.framework at the above location. A "Get Info" on the linked binary reports that it is a member of both Targets.
If I right-click on the Sparkle.framework file within the "Copy Files" build phase of the duplicated Target, and select "Reveal in Finder", then the correct Sparkle.framework file is shown. The required file exists at Sparkle.framework/Headers/Sparkle.h
If I switch back to the original "MyApp" target, it builds and runs successfully.
Am I doing something obviously wrong here? Thanks.
[EDIT - SOLVED]
I had a look at the Build settings for each supposedly-identical Target.
Under "Framework Search Paths", the first Target had this:
$(inherited) "$(SRCROOT)"
But the duplicated Target had this path:
$(inherited) \"$(SRCROOT)\"
It appears that Xcode incorrectly escaped the path during the duplication process. Ouch.
I know you have already solved this issue yourself, but I thought I'd share my fix for this issue (as it has happened to me several times). I've always been able to get rid of this error by deleting the file in question and just recreating it. I have no idea why this works... but, as is often the case with XCode, there seems to be some Voodoo at work.
Build Phase copy is still broken in 12.5! It does only copy a few of the source targets build phases. What a crap IDE.

How to have Xcode always copy files (even if they have not been detected as modified) when building?

I am developing an application which uses .js files stored in the Resources/javascript folder of my application bundle. In my Xcode 2.5 project I have created a folder reference (not a group) to my javascript folder, which automatically added the folder to the Copy Bundle Resources build phase.
The problem I have is when I modify my .js files, I need to clean my project then re-build it for the modified .js files to get copied into my application bundle when building. This is very time consuming since I re-build the whole project just to get an updated .js file in my app bundle.
Could someone tell me how to get Xcode to always copy specific files in the build phase?
Thanks in advance!
You could right- or control-click the file (in the project file list) and click "Touch" before building (manual) or add a script build phase to the target that calls "touch myfile.js" and place it before your Copy Files build phase (automatic).
Add a new Copy Files Build Task to your target.
Right Click (Control Click) on the target, Add -> New Build Phase -> New Copy Files Build Phase.
In the Dialog select the destination that you want the files to be copied.
This will create the phase under the target. Drag the files you wish to copy to the phase.
There's an excellent walkthrough here of a build phase script which automates the 'touch' and saves the manual step of specifying each file you want included.

Resources