store folders in package contents (bundle resources) in xcode 4.0 - xcode

I need to store a folder in the package contents, not all files in the project all in one root folder.
How can I do this in XCode 4.0?
Right now I am going to the Build Phases > Copy Bundle Resources to attempt these changes.

Create your folder in the filesystem, then drag it to the resource folder in XCode. In the following dialog select create folder reference for any added folder. The folder should be blue. This folder is copied to your bundle with its contents.

Related

In Xcode7 when I new a folder in the project base folder To the project,then the folder is blue

when you new a group we can not find a real folder in the project,So we new a folder and add it as files to the project.But this time in Xcode7 I AddFileTo my project ,the folder is blue .
You are adding the folder as reference. when you add the folder, make sure you check "Create groups"....not "Create folder reference". See the following Screenshot.

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

Resource files in subdirectory are copied to root directory of the app bundle

I am not sure whether this is expected or it is bug.
I am trying to create the same folder structure in disk as that in XCode. I use the following steps to add resource files to my project:
Create a Resources folder under the root folder of the project.
Drag the Resources folder to XCode, which creates a Group for the folder.
Drag my resource files from Finder to the Resources folder in XCode.
And now I can see all the resource files are listed in Build Phrases->Copy Bundle Resources.
The weird thing is that [[NSBundle mainBundle] pathForResource:#"book" ofType:#"epub"] returns a file path that can be located, while [[NSBundle mainBundle] pathForResource:#"book" ofType:#"epub" inDirectory:#"Resources"] returns (null).
From the Build Results window, I notice this line:
CpResource MBookReader/Resources/book.epub /Users/neevek/Library/Developer/Xcode/DerivedData/workspace-fykuaikryknuhxgevcdtspkspptj/Build/Products/Debug-iphonesimulator/MBookReader.app/book.epub
cd /Users/neevek/workspace/xcode_projects/MBookReader
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks -strip-tool /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip /Users/neevek/workspace/xcode_projects/MBookReader/MBookReader/Resources/book.epub /Users/neevek/Library/Developer/Xcode/DerivedData/workspace-fykuaikryknuhxgevcdtspkspptj/Build/Products/Debug-iphonesimulator/MBookReader.app
which shows that Resources/book.epub file is indeed copied to MBookReader.app/(the root directory of the app bundle).
Now Resources is a real folder in disk, why the folder itself is not copied?
PS. I am using XCode 4.3.2.
When adding your Resources folder to Xcode, choose "Create folder references" instead of "Create groups for any added folders" in the sliding window.
That is, replace the 3 steps in your question with the following ones.
Create a Resources directory under the root directory of the project. Organize your directory structure inside the Resources directory the way you want it to be.
Drag the Resources directory to XCode and select the Create folder references option.
You're done. Xcode will copy the contents of your Resources directory recursively into the bundle.
You might have trouble further down the road when Xcode doesn't copy a modified file somewhere inside the Resources directory. A clean build usually fixes this. Alternatively, you can remove the .app file before building. This will not cause unmodified source files to rebuild, but will force Xcode to copy all of the resources anew.

Xcode - Dealing with folders by code

When you add a folder that contain subfolders and files to the Xcode project, the Xcode ask you about the folder option:
Create groups for any added folders.
Create folder references for any added folders.
I want to download the folder from a server. When the download is complete, the folder option will be 1 or 2? How can I set the folder option to option 2?
When Xcode references a folder, it uses whatever files are stored at that location on your local disk. If you download a new file to that folder or copy a file into that folder, it will show up in your Xcode project. If you change a file in that folder (by overwriting it in the Finder, or by using another app to download another copy of the file over the existing one), Xcode will use the new one.

Resources