How can I control which files are included in the application bundle? - iphone

If I include files in my Xcode project, how can I control or specify which files are included as a part of the application's bundle?
For example, all the PNG files I add to the project always wind up in the bundle. Conversely, the .m and .h files are not.
How can I control or specify which are or are not included?
If I through in something - like some random data file - how do I know if it gets built into the bundle or not?

Right click on the file (either class file or resource file) which you don't want to include, select Get Info. Go to "Targets" tab. Check/Uncheck the box near the target name, for include/exclude the file.
Notes:
1) header files are by default excluded from the target. Only source files (.m or .mm or .cpp, etc) & resource files (.png, .jpg & all others) are required to be include/exclude from target.
2) If you exclude any source file from target then by default it's header file will get excluded & that source file won't compile.
3) Similarly, if you exclude resource file, it won't be copied into the bundle & thus any reference in your code to that file, will result into the crash of the application.

You control what gets copied where during a build by controlling what's listed in the various Copy Files phases of the build target.

To control what is copied you can do the following:
Click the image you're concerned with
From the File menu select the Get Info option
Select the Targets tab
Select the targets you'd like to have the resource copied to, or deselect to not copy

In general, files (like .h & .m) are the exception. If Xcode doesn't know something special to do with them (e.g., compile), they're just included.
At some point, I thought Xcode would run a special rule on even PNGs (to optimize their size).

Related

How to physically move the Prefix.pch and Info.plist files

I've reorganized almost all the files of my project in the physical directory structure so that they are all in one physical directory. But, I can't seem to move the Prefix.pch or Info.Plist files without problems.
My method of moving the other files was to
(1) delete their references in Xcode,
(2) physically move them with Finder to their new physical directory and
(3) in Xcode to add them back into the project.
Are there settings somewhere in my project that have specific knowledge of the physical locations of these two files that I have to update as well?
There are build settings called Prefix header and Info.plist File. You have to change the path to the new path for these settings also.
And to add on, you don't have to delete the reference and add again. After moving the file , you can click on the Xcode reference of the file. Then in the file inspector there is a small rectangle box near the 'location' setting. If you click on this you can specify where the file actually exists.
I want to do the same with you. You can do it like what you want. But after that you need to change the "Build Setting" for the pch and plist file.

How to correct missing files in xcode iOS project

I have a project with some missing files. The files are their own folder on the same level as the iOS app project folder. Not sure why but the files are showing up as "missing"
Is there something I can do to the Library Search Paths (see screenshot below) so they find them correctly?
fyi: I inherited the project, so it was just sent to me. I try to build it and get all those files missing.
thanks for any help :)
It's nothing to do with library search paths, they are used to find libraries to compile against; they're nothing to do with source files contained within your project.
They are missing because your project file is trying to reference a location for the file that doesn't exist. You have two options:
If you have all the missing files on hand in Finder, you can delete the references to them in Xcode, and re-import them. Do this by dragging them back into the project from Finder.
You can instead 'fix' your project file, to have it refer to the right place. To do this, use the File Inspector on the right, and under Location, select the 'box' icon (not sure what it is, but select it), and relocate your file.
open the folder in which these files are present then drag and drop the missing files in you project. check the "copy items into destination group's folder(if needed)", choose "create groups for any added folders".
Remove these files from the project view (list on the left side), drag them back into the project and make sure you don't select Copy to project, but you also have to check which target to put in.

Changing app target name makes PNGs disappear?

Trying to change the name of the app from the development name to the production name, I renamed the target as a first stab. The PNGs in the app disappeared. I then changed the target name back to the original name and re-built, but now the PNGs are still missing.
I'm looking at step-by-step guides on project/app name changing, but I don't want to proceed until I'm unable to undo whatever this did.
Does anyone know why the images would now be missing? Even after I changed the name back?
I'm assuming there is some path based on the target name and that changing the target name triggered other changes not reversed by simply changing the target again?
Many thanks
why not just use Product Name under Target -> Build Options. So you don't have to change the target name! :)
Type in the name of your project in the finder, and double click on the project folder. Inside that folder (it may be in a folder inside that folder, like resources or something but on my computer its all in the project folder) look for .png images. These images are the images that are in your project. Delete every image inside here, or just move it somewhere else. If your app has the .png files inside the project folder, but the files are in your resources folder, you won't be able to put in the same image in your resources folder because your project (your app) says its already there, even though its just sitting there and your not using it...
So delete all the .pngs inside your project folder, then open up the app with xcode and drag the image files you need into the resources folder. Hope this helped.
Each file in a project can be included in a target, when you changed the target name, its possible that png files lost association to the target. right click on the folder which has the png files, and click on get info, there you will be able to select which targets this folder is included in, mark the check box for your intended target, and the files will be included again in your target.

load XML in iPhone App

I have a problem.
I have a XML and a project (XCode 4.1).
I must build my app with a XML file into this.
Now, where i put a XML file in my project?
In the XCode 3 there is a resource folder but now i haven't this.
Thanks
There should be a Supporting Files folder in your project. You might organize any extra files in this space.
You can put the XML file anywhere you like, so long as you subsequently make Xcode aware of its whereabouts. However, the most straightforward way is probably as follows:
Either:
Make a new group by going to File->New->New Group or
Use the existing Supporting Files group.
Drag the XML file into the group. Xcode will then present an add file sheet. Make sure that "Copy items into destination group's folder (if needed)" option is selected and your target is checked in the "Add to targets" list. Click "Finish".
That's it. Xcode should automatically add the file to the project and include it in your app's bundle.
Should you need to add the file "manually", you can select your project in the Project section of the Navigator pane (press Cmd-1 and select your project at the top left), select your target in the list (just to the right), select "Build Phases" from the tabs at the top and add the file to the "Copy Bundle Resources" build phase.
Just put it in Supporting files group.
I think this should help you.

iPhone & iPad - two icons and two plists?

I have a product with two targets, one for iPhone and the other for iPad. I will build two separate applications, not universal.
As I will have to have two icon.png files for the application's icon, as they differ in size, as I see I will have to have two info.plist files. right?
I have created two copies of the info.plist file, named iphone-info.plist and ipad-info.plist. I have right clicked each one and assigned them to a specific target.
Now, when I compile I see this error:
Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'iPhone-Info.plist'.
If I remove the target assignment from both info files, the error vanishes.
here are the questions I have:
If I cannot set a target for info.plist, how each target knows which info.plist to use?
Is there another way to make each target have its own icon without using two plists?
thanks for any help.
If you get info on a target, click the "Build" tab, and type "plist" into the search box, you will see that the Info.plist file it expects to build that target with is listed in the Build settings. Change that to point to the file name of each plist file you want for each target.
Setting the target for each plist only adds it to the target build like any other file - to actually tell the app to use a particular plist file as "THE" plist file with relevant info, you also need to set it in the target settings.