Xcode 4 embedded resource prevention - iphone

In XCode4, is there a way to have a 'resource' (i.e. a CSV used to load a sqlite database) that is there for project purposes, but not have it compiled into my project? So my final app doesn't include it? I can't seem to see to to have this facility.
Thanks

Assuming you do not want the file get into your .app file, One solution i can think of is, do not include 'Target' when adding the file to the project. If you want to exclude your already added file then
Choose the target
Go to Build phases
Expand copy bundle resources
Select your resource file and remove it.

Related

How do I add files to the Copy Bundle Resources build phase with an Xcode4 Project Template

I'm working on an Xcode 4 project template and I'm struggling with controlling the files that get added to the Copy Bundle Resources build phase--header files get added that I do not want to be copied into the project bundle and a file that I do want to be copied does not appear in this list (a custom .framework file that contains both the static library and image resources).
It seems like Xcode automatically builds contents of this build phase from the Nodes section in the project template; if it's a .framework, it automatically gets added to the linked libraries, if it's a .m, it automatically gets added to compiled sources, and everything else gets added to the Copy Bundle Resources.
I'd be grateful for any direction on this one!
Update:
To clarify, I'm attempting to create an Xcode project template that, when used, creates a new Xcode project that includes the specified files from the template in the Copy Bundle Resources build phase.
This should help. After the Class-Resources key-value pair, you can add files somehow. I couldn't figure that out but I'm sure you can find it somewhere.
EDIT: Actually, i think an easier way is to in the Definition part, after the Path key, add a TargetIndices key (an array). With some experimenting you should be able to find out what value to put on one item of that array to put it in the Copy Bundle Resources build phase.
Yes, Xcode tries to manage this for you. If after adding a file, it did not did what you want, then change it. It's guesses are "usually" correct "most" of the time. :)

iPhone project - collect files into one place

Sorry if this has been answered before but all my searches do not return anything related to this.
Is there a way to collect all the files referenced in a project and save them in the procject folder automatically? Rather that having links to places where you may accidentally delete the files.
Thanks,
Eds
Xcode doesn't have a particular feature to support this, but when you add items to your Xcode project it does give you the option to copy those items to the project directory. Otherwise you need to manually copy the items to a common location.
What do you mean collect all the files? Do you mean your external files or class files. Your external files like images or audio/video files should be added into Resources directory, it does not matter where is the root directory of these files. Then, you can access with their name in the project.

Renamed Files Still Exist in Xcode

I'm making an iphone app that displays a random picture chosen from pictures in Resources.
I have renamed some files for categorization,
but running console shows that file with a new name and file with old name both exist as separate files.
Of course, I can't see the file with the old name in my Resource folder, nor in the original folder where the pictures are.
Kinda freaky...
How could I remove the files with old names and make it a norm to not keep another file with the old name whenever I rename a file?
Please help me out.
Thanx.
Expand your Target and remove the images from Copy Bundle Resources.
I'm not sure I understand your question correctly, but I recommend cleaning your targets from the project menu and resetting the simulator.
You can also select all the new files in XCode, right click and select compile.

Using resources with the same name in Xcode

Is there a way to add multiple resources with the same name to an Xcode project and have 1 of them take priority over the others?
Example:
I added 2 files, both called icon.png, to an Xcode project. They are on different folders in the file system (Folder1/icon.png and Folder2/icon.png) and on different groups in Xcode. Is there a way to tell Xcode to have Folder2/icon.png take priority over Folder1/icon.png? And if only 1 icon.png exists, then use that one.
Thanks.
EDIT (2010-12-23):
You can have multiple files with the same name in an Xcode project even if they are not in separate folder references, but they are in separate groups. Once compiled, the app bundle (which will be flat with no folders in it), will only have one copy of the file (icon.png). How do you pick which copy of the file to use?
I was told that you can do this for BlackBerry. It works something like this: The compiler will go down the list of files in the project and start adding them to the app bundle. If it sees a duplicate, it will overwrite it (or not), so the files at the bottom (or at the top) will have higher precedence and will be the final bundle.
This can better easily be solved by using folders within a resource bundle in your Xcode project. Take a look here: http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html
Wait a second, since you specifically mentioned icon.png, are you trying to supply different iDevices (iPad, iPhone4, iTouch3...) with different icon images?
If yes, check this out, http://d.pr/W2w0 , Apple has already provided a way for us to finish this task with convenience. All you need to do is following a specific naming convention.
What we do if we have a situation like this is:
We have several subfolders on the file system level of the project dir and add them to XCode into separate groups.
This works well. For actually building, we try to avoid Files with the same Name in one target. Icon.png and iTunesArtwork are only added once in every target.
It just proved to be a Maintainability Nightmare

How do I properly add existing source code files to my Xcode project?

I'm new to iPhone development and I'm still getting familiar with the Mac dev environment, including Xcode. I want to add some 3rd party code to my iPhone project, but when I add the "existing files" to my Xcode project, I'm presented with a dialog box that has far too many options that I don't understand and, as such, my project isn't working. When I #import headerfilename.h, I get a build error that reads headerfilename.h: No such file or directory.
alt text http://joecrotchett.com/images/misc/fileadd.jpg
Can anyone explain to me what all these options mean or give me a link to some documentation that can? I'm having a hard time finding anything in Apple's docs.
Which options do I want to choose to add existing source code files to my Xcode project? I should note that the source code files that I'm trying to add are located in my project/Classes/frameworkname/ directory.
After they're added, do I need to reference this new code directory in my project settings anywhere (i.e. some kind of header file directory variable)?
Thanks so much!
Update: I found the following answers/responses on the apple dev forums that were very useful and helped me fix my issue...
To make it simple :
- if you do not check the copy option, the file stay where it is.
- if you check it, it is copied in your project folders In the first case
(what it seems you are doing) you need
to tell the compiler that the header
files are in another directory :
- project info -> build -> search paths -> User Header Search Path : add
the directory from where you took the
header file Hope this will help
You have discovered the most confusing
dialog box that ever came out of
Cupertino. Six years of Xcode, and
this thing still is partly a mystery
to me. To even get that far, I had to
make many test projects to try and
reverse-engineer what this thing does.
The "Copy" box means that it will copy
the files as they are right now, into
the project. If this box is not
checked, then it just references those
files during a build and copies them
as they are at THAT time. For source
code, you want the Copy box checked.
The "relative to" is a total mystery
to me and I can't help you with that.
I usually leave it however it is
already set. Does it mean relative to
where they are on disk, or the
arrangement in Xcode, or in the
bundle? Who knows. The last 2 radio
buttons SEEM to mean that it will
either re-create the folder structure
of the folder you are adding, or just
put "fake" folders in Xcode that point
to the real folders. This is probably
your problem - you are adding source
code that is not all at the top level,
and when it goes to find it, it does
not re-create the hierarchy. Others
can supply a better way, hopefully,
but what I would do is put all of the
source in one folder and add that,
using the Copy box. Then in Xcode you
can make whatever bogus folders you
want and put the source file names in
those fake folders.
This is from the Xcode user guide:
"The project navigator shows projects, groups, folders, and files:
The project or projects in your workspace window are the highest level
of the hierarchy in the project navigator. Open the project’s
disclosure triangle to see the groups, folders, and files in the
project. Select the project to display the project editor, where you
can view and edit project and target settings.
A group appears in the project navigator as a yellow folder icon. The
group does not represent a folder on disk. Although you can organize
your project in Xcode to reflect the organization of files on disk,
moving files into and out of groups does not affect the content of the
folders on disk, and moving files on disk into and out of folders does
not affect the content of the groups in the project navigator.
A folder is a reference to a folder on disk and appears in the project
navigator as a blue folder icon. The contents of the folder in the
project navigator reflect the contents of the folder on disk. It’s
important to note, however, that the files that appear in a folder
icon in the project navigator are not part of your project unless you
have added them to the project explicitly (in which case they appear
directly under the project or in a group, as well as in the folder).
You can view and edit the files in a folder, but to move files in and
out of the folder you must use the Finder.
A file in the project navigator is a reference to a file on disk."
I think usually the default option is the best one. If you want to add into some group, you can tick on the "Copy Item to Destination group"
You don't have to change any project settings after adding
And if you want to add the whole framework code, please choose add existing framework
Copy items into destination group's
folder (if needed)
Well, only if you want it to copy the files. If you are happy with their existing location and don't want it to copy them, don't select it (that's what I do).
Reference Type:
A total mystery to me
Text Encoding
Self explanatory
Recursively create groups for any
added folders Create Folder References
for any added folders
Leave this as the default and then organize the folders in your Xcode project any way you want.
Add to targets
If you add an additional target to your project, e.g. for iPhone vs. iPad versions, then not noticing that it has by default added the files to just one of them (at random?) can cause headaches.
Also, make sure you add the new header directory to your search paths in Project Settings > Build > Search paths. I think that's what's causing your problem.
Hope this helps, I remember how confusing this was to me at first.
If you want to add an Framwork Bundle, just add is as one. Add -> Existing Frameworks