Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding files in Xcode 4: ensure the path is relative to the project/how to change path?

In Xcode 4, I can't add files/resources to my project without having the Relative-to-Group path end up something like: ../../workspace/Project/Resources/thing.png

Ideally I would have Resources/thing.png.

I have tried every possible combination of adding folders, files, making new groups. I wish to keep my resources in a folder within my project directory. If I omit the folder, clearly my assets will be relative to the project — just "thing.png" under the project's root.

Is there any way to change the path of a single file (I already know how to 'change the location the group represents') such that I can set the location manually (such as in Xcode 3, where this path crap would happen as well).

like image 578
h4xnoodle Avatar asked Apr 05 '11 21:04

h4xnoodle


People also ask

How do I change the path of a file in Xcode?

Clicking on the Folder icon next to the name will bring up an open panel from which you can choose the correct location of the file.

How to add Existing files to Xcode project?

Xcode offers several ways to add existing files and folders to your project: Drag the files from the Finder into the Project navigator. Click the Add button (+) in the Project navigator's filter bar, and choose Add Files to “projectName”. Choose File > Add Files to “projectName”.

How do you specify relative paths?

A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.

How to add a new folder in Xcode?

Find your ViewControllers in the file system. Before clicking Add make sure that the option Create groups is selected. Click Add.


1 Answers

My dirty, but simple solution to this:

  1. Reveal the project in finder
  2. Rightclick the *.xcodeproj file and choose "Show Package Contents"
  3. Open the project.pbxproj file with a text editor (e.g. TextWrangler)
  4. Find & Replace the absolute "../../../whatever/this/path/is/in/your/case/" part of all file and/or group paths with ""
  5. Save the file and open the project in Xcode (it even worked when the project was already opened in Xcode)
like image 78
Rene Kretzschmar Avatar answered Nov 25 '22 11:11

Rene Kretzschmar