Adding files to separate targets in Xcode 4 - iphone

Since upgrading to xcode 4, I can't find where to specify what Target a resource belongs to. Previously, I selected the file and hit command+i, but this now seems to run the program, rather than bring up the info box for that file.

Select the project file in the document explorer. On the Right margin of the Xcode window make sure to display the right drawer view if it isn't already there (it usually has Object library and Quick Help). In the top margin, click on the icon that looks like a document (rather than the one with the waves that is quick help). The target membership and the other info from the old Get Info command is there.

Select the project file in the document explorer pane, select your target from the list, select the build phases tab and add/remove your resources in the copy bundle resources phase or source code in the compile sources phase.

Right click on a folder (eg. resource) on the document explorer (which is the left column with all your files and folders in your project), select Add Files to "Project Name". Below you will see check boxes that determine the file's association with each target.
#makdad - This also works for the 'blue folder' situation.
Note: if you already have a file in xcode, the only way you can add targets to a file that's in a 'blue folder' is to remove the file and follow the steps stated above.

Related

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.

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.

How to change Xcode Project name

I have developed my app in Xcode for iPhone, in start I have just named it without secnec now I want to change my app name I have replace my old app name with new one as I have found the name in my app, but its still giving me one error...
Desktop/New name/old name_Prefix.pch: No such file or directory
when I have change oldname_prefix.pch with newname_prefix.pch ..
For Xcode 4 or later:
Open a project
Select Project Navigator
Highlight project name
Single click on project name
For Xcode 3:
Open a project > Menu > Project > Rename ...
There is no need to change the name of the project in order to change the display name of the application (which is what you see on the home screen of the iOS device, in iTunes, etc.). Simply change the "Bundle display name" in your info.plist from the default "${PRODUCT_NAME}" to whatever you want it to be. The name of your project is invisible to users, they only see the "Bundle display name."
click on you project in project explorer and again click on your project on right side and there you can see project name as shown in the figure
On the left side expand Targets
Double click on your target and then select build tab in the newly opened window
on the top right there is a search box. Type - "Product Name"
Now look below, under packaging section, you will see Product Name
Change it and clean rebuild, your new app name should be changed by now.
Goto
youname-Info.plist
Change Both
Bundle name and Bundle display name to your preferred file name.
Done.
For changing application name only (that will display along with app icon) in xcode 4 or later:
Click on your project file icon from Groups & Files panel, choose Target -> Build Settings -> Packaging -> Product Name.
Click on the row, a pop-up will come, type your new app name here.
For changing Project name only (that will display along with project icon) in xcode 4 or later:
Click on your project file icon from Groups & Files panel, choose Project(above targets) from right pane, just see at the far right pane(it will be visible only if you have enabled "Hide or show utilities").Look for project name.Edit it to new name you want to give your project.
Delete your app from simulator/device, clean and run.Changes should reflect.
That's it
ohho's answer is perfect:
For Xcode 4 or later:
Open a project
Select Project Navigator
Highlight project name
Single click on project name
BUT, if you only do this, once you try to debug on a new device, you will find an error:
file not found: /Users/someuser/Library/Developer/Xcode/DerivedData/OLDNAME-akbwbarcniqxytctbebckkelkbxs/Build/Products/Debug-iphonesimulator/OLDNAME.app/OLDNAME
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Then you need to do one more step:
Select target on the left panel
Choose the oldnameTests in Targets
Select the Build Settings Panel
Search for "TEST_HOST" and change the old value to the new.
Good Luck and Have Fun
Here is Apple's step by step visual guide to change name of Xcode project.
To change name of workspace just rename it.
in xcode 4.4, you have to click on the project at the top of the navigator (left panel). Then click twice on the target in the second column to highlight the target name. Then you can change the product name. You will also need to modify the archive name when you go to create an archive. To do this, you must edit the scheme, click on Release, and then change the archive name.
I am using xcode 4.3.1 and tried to change product name as Quakeboy said above in the bundle setting, but it led to reading error. I was stuck in this error for an hour and now it is working well. I simply made the product name blank then retype the older name that I had before. building succeeded again!
Note to anyone who like to change project name : you don't have to change the project file name the bundle display name will be display to users so just don't hang out with this issue too much. can be wasting time.
It creates an organizational nightmare to have project names that don't match the bundled name. But when I use the "click on project name and answer yes to let xcode rename all of the references" technique, all of the nested folders for the project on my hard drive still have the old project name. Why aren't they renamed to match?
If I change those folder names, I'm pretty sure it will mess up all of the project links. I am not going to take the chance, unless someone can suggest a way around this.
Select the project in the Project Navigator (Command+1) and open the File Inspector in the right sidebar (Command+option+1).
There, change the Project Name.
Xcode 3.2.5:
In top menu bar, Project>Rename...
I tried by changing the Project name in Project Navigator, but you need to follow through with the all the step outlined here!!!.
I did not follow the second step and this broke my app, had to rework a older version which took two days, see my SO post here.
I tried ohho's answer and it didn't work but found another solution. You can open your Info.plist file and go where it says' "Bundle Name" and change to your new name that will be shown in your launcher. I hope this wrks
Simple step
1.Select the project target left side on top of all folders and files
2.Single click on the project again it will allow you to change the name
3.type as u want the name of the project and the name of the app
4.Press enter. it will ask to change every where accept it
5.same procedure do on the folder as well all place the name will be changed. i did it today
Just in case this helps someone, I have a shell script (xcmv.sh) with the following:
#!/usr/bin/env bash
mv $1 $2
mv $1.xcodeproj $2.xcodeproj
mv $1.xcworkspace $2.xcworkspace
LC_ALL=C find ./ -type f -not -path "./.git*" -exec sed -i '' "s/${1}/${2}/g" {} +
I then drag this file into the project directory and do:
sh xcmv.sh Starter MyProject
This changes the project name, the workspace name, plus any and all references to the old name in the project files, code files, plist, and so on.
As the sample indicates, I often use it to rename one of my various "starter" projects to the desired project name.
Note the git directory (if it exists) is ignored.
This video shows a developer renaming an Xcode 6 project. First single-click the project name to change it, then make sure to also set the host application for your test build target.
https://www.youtube.com/watch?v=ZHr1vjkTxC0

separate directory for iphone resources

iPhone resources by default show up in a "Resources" group that's visible in the main xcode project view. I want to be able to put them into an actual, physically separate directory at some arbitrary location on my machine decided by me. Interestingly enuf, the default "Classes" group is an actual, physical directory but the "Resources" group isn't.
How can someone tell me how to do that?
TIA,
Howard
Right click on Resources, add existing files, choose your directory
and select "Create Folder References for any added folders".
Voilà.
An alternate approach is to start with a directory in your project with some files, drag it into Xcode and have it create the folder references for you. Anything you add within that folder reference is automatically put in that subdirectory.
Both the abovementioned approaches are just how-tos. These operation will transform into build setting. Here is how you can change (or at least just view) the setting on XCode.
If you are using XCode 4+, check the project icon, then select your Target. In Build Phases tab, looking for "Copy Bundle Resources (x items)" category. In it, you should have your folder there. If no, click "+" button.

Xcode Groups & Files: How can I copy files from project A into project B without getting crazy?

For some reason, the representation in Xcode "Groups & Files" does not match the file hierarchy in the folder where all my real project files are. And for some reason, I can't copy a entire group or even single file and put that into another project. So I have a nice hierarchy of images within "Groups & Files", but all thos ordered images are unordered like a big mess in just one giant folder full of stuff on my file system. Really horrible ;)
So now I wanted to put all my icons into another project, but I cant just copy the Group "img > gui > icons". I have to pick every single icon image from my file system, where icons are mixed up with a few hundred other images and files.
Is there some hidden option I can activate so that Xcode will manage to reproduce the hierarchy of "Groups & Files" inside my project folder on the file system? Or how else could I copy those files?
It's not really possible to transplant a Groups hierarchy intact from one project to another. Some suggested approaches:
If the files you want to bring across are the vast majority of the project, just clone the project and delete everything that's not the files you want to copy.
If it's a lot of files in a small number of groups, then set up the groups in the new project, and drag-copy the files from the old project groups into the new project groups
Write an AppleScript to move the hierarchy across with a recursive-descent algorithm
◆◆ Open both project.pbxproj files as text files, and carefully copy the File References and Group References from one to another.
Steps:
1.Open up the group in Xcode
2.Select all the items you want to have in your other project
3. Right click and show in finder.
4. Copy those files to a new folder in Finder
5. Now drag and drop those files in the new folder in Finder to your newly created group folder in Xcode on the new project.
6. Accept the copy instructions on 'add file' action in Xcode
Copy icon files in a filtered-Finder window to an "icon-only" folder. Then import them into your new Xcode project. Repeat for any other categories.
See my previous question here.
Also, file a bug with Apple to let them know you'd like the option to have groups represent the folder structure on disk.
I am late, but this is a possibility:
Open the directory of your project using Finder. Copy whole directory (in Xcode its used as a group) into your new project. In Project navigator, right click and press "Add Files". In dialog box, select copied directory and its done.