Can I mass replace hundreds of references to files in Xcode 6? - xcode

I have an iPad app and I've recently replaced hundreds of PNG's with JPG's to reduce the project size. Now Xcode is rightfully complaining that there are 1000's of missing file references. I can easily select the file, edit its properties and change .png with .jpg and All is Fine. However I will be an old man when I'm done.
Is there a way to mass replace all missing references in the project? Or can I mass remove all missing file references so I can re-add them?

Yes, edit your project file manually, using BBEdit or some other text editor with a search and replace feature.
Right click on the whatever.xcodeproj file (which is really a folder), and select Show Package Contents, in there, you'll see a project.pbxproj file. Edit this file in your editor, and do a search and replace for png to jpg or whatever. You can get fancy with your search and use a regex to select specific paths if you like, rather than doing every png file. That only matters if you still have some png's in the project.

Related

Xcode can't find source files

I'm using Xcode 8. I recently inherited a project with several hundred files (including source and image files). I rearranged them on my local drive and the file names (appropriately) become red in the folder list on the left side of Xcode. I selected files/folders in this folder list, click on the "Hide or show Utilities" button to display the "Identity and Type" pane on the right side of Xcode, clicked on the little folder icon next to the Location, and selected the files'/folders' new locations. The text in that pane was updated to the new location and the file/folder names changed from red to black. So far, so good. I did this to all of the file/folder names until none of them were displayed in red.
However, when I go to build the project, I get numerous warning messages similar to, "image.png /Users/Me/Project/images/image.png is missing from working copy." The path shown in the error message is the file's OLD location. When I look at that image in the file list, it is displayed in black. When I select that file and look at the Full Path in the pane on the right, it shows the file's current location (e.g., "/Users/Me/Project/images/newfolder/image.png"). I'm unsure where in the project the old location is being stored. FWIW, I've tried Cleaning the project...
Thanks for insights.
So here is an approach that is perhaps not for the meek, yet it is something I do more often than one would expect to fix Xcode project files. I tend to be the one designated to do this on the teams I work with ... manually editing the project file. The .xcodeproj file is really just a special folder. The actual project file is project.pbxproj.
First back up the project file. Your choice on if you want to do the complete .xcodeproj or just the project.pbxproj.
Use your favorite text editor and open up the project.pbxproj file.
Search and replace the prefix to your path. For the sake of this exercise, you should try and keep your path as similar as possible to make it easier. For example, if the hardcoded path is /Users/Me/Project/Images/newfolder/image.png and all prefixes are generally "/Users/Me/Project", you can just do a search on "/Users/Me/" or "/Users/Me/Project" (the latter if you want more safety) and replace with "/Users/You/" or "/Users/You/Project". Note I am not searching on "Me" and replacing with "You". You want to search and replace but as controlled as possible.
Once done, save and open the project. If the project doesn't open at all, it means you messed something up. Start over. Note that changing the paths should not be sufficient to break the file. It will probably mean you accidentally added or deleted something.
If the project file opens now build. It should hopefully build.
Okay, so that gets you into a buildable state. Now you really want to fix things. Whomever did the project was a knucklehead for using absolute paths.
This next part will be tedious. There are probably ways to do this manually, but I'll leave that to an exercise for the reader right now. In file inspector within Xcode, you will want to change files to be anything but "Absolute Path". Here is an example, you can see the location is "Relative to Group".
Essentially you are going to have to around to Groups and files and fix things up to not be absolute. Make sure you backup incrementally and can build.
Wait, but unfortunately there is more. You'll then need to go into Build Settings to see if things are absolute paths. Then you'll need to decide how to adjust for that. For example, it is not uncommon for 3rd Party frameworks to be added with absolute paths.
Or I suppose if you want to, you can just get it working and skip the latter part of this and damn everyone else...

How do I save and load all files in a sublime text session as a 'project'?

I've read that you can save a ' project ' but apparently I'm doing it wrong.
What I've done is...
Create a js, html and css file and use view/layout with 3 columns so
each file has its own section of the layout.
I then went to Project / save project as / and saved the respective file in
a directory
I assumed that all files should be saved in this directory along with a file that I can click that loads them all up to reflect the workflow.
Apparently sublime has a different idea of how this should work and I do not understand it.
Essentially, there are two parts to a Sublime project - a .sublime-project file, and a .sublime-workspace file. Please see both the "unofficial" docs and the official website for information regarding projects, and the setup of .sublime-project files. These files are JSON-formatted and contain paths to any folders contained in your project, project-specific settings, and project-specific build systems. This file can (and should) be edited to customize the project to your needs. Double-clicking this file (after associating its file type with Sublime, following the procedure of your operating system) will open the project, any open files within it, and any folders you've added to it (by selecting Project -> Add Folder to Project).
The .sublime-workspace file is also JSON-formatted, but is saved automatically by Sublime and shouldn't be edited unless you really know what you're doing, and even then you probably shouldn't edit it. It contains all sorts of meta information about the project's history in Sublime, which files were open and in what order/pane, previous contents of searches, find/replace, etc., your file history, settings for various plugins like SublimeCodeIntel, and lots more. By default it is hidden when viewing the contents of folders in the Side Bar, and when double-clicked it will try to open the project instead of opening for viewing/editing, so there are several measures in place to prevent your playing with it and potentially screwing up Sublime.
.sublime-project files can be saved wherever you want, but the folders and files contained within it are not necessarily saved in the same place - they stay wherever they were saved. It usually makes sense to save them in the project's root directory, so if you have a filesystem like myhomedir/projects/web/SweetWebsite/ containing html/, js/, and css/ subdirectories, you might want to save your project as .../SweetWebsite/SweetWebsite.sublime-project, just so you know at a glance what files/folders are probably in it. However, you could save SweetWebsite.sublime-project in myhomedir/Desktop for all Sublime cares, and it would work exactly the same way. While it is possible to have unsaved files in a project, of course it's always best to save your work early and often, so you don't lose anything.
Hopefully this helps, please let me know if you have further questions.

Programmatically rename an XCode project

I know one can rename a project by slowly double clicking the project name but I was wondering if it's possible to automate that through the command line (any language, possibly Apple Script) ?
Renaming an Xcode4 project is quite easy.
Click on Show the Project Manager to see the top level project file on the left side.
Click on the project name (here DeeTeeSaver will be changed to DeeTeeSaver2) in order to edit it and enter the new name.
It takes a second to let Xcode4 find out which parts have to be changed.
It then displays a dialog which parts will be changed. Simply click on Rename.
That´s it. No need to fondle around with AppleScript.
You might miss important parts inside the bundle.
Greetings from Switzerland, Ronald Hofmann
You will have to manipulate the .xcodeproj file, which is in XML format.
In my build process I have placeholder names that I simply search & replace with a command line app. If you need a generic solution you will have to parse the XML format (which is undocumented but not that hard to grasp).

Why can't I delete files from my XCode project?

This is probably a very easy question, but I'm having trouble deleting resources from my XCode project. I added them using "Create Folder References for any added folders" so that I could import a whole offline HTML site with its correct folder structure.
Unfortunately, now it has been added like this I don't seem to be able to delete individual files in the structure (it's not available from the Edit menu).
Can anyone help please? Thanks!
That isn't how folder references work. The idea is that its only a reference, you can open files within it and save it from those editors, you can delete or move the entire reference throughout the xcode project, but you can't actually edit it - its read only as far as xcode is concerned. Likewise, you cannot restructure it (move internal files around).
I'm not to sure why apple decided to make this the case, but apparently they have.
If you want to know how one might use the xcode folder system, here's how I tend to use them with my projects:
Whenever I subdivide code into folders, when I drag them into my project I click "recursively create groups for any added folders". If you do this, you any changes you make within xcode will not reflect the actual file itself. As far as I know, there is no way to do this. What does happen then is that when you add a new code file to it, the directory starts off in that file by default. ie, you don't need to navigate to it manually when you create a new file.
I use folder references whenever I'm working with content for an application I'm using. This way, I add all my images, folders, configuration files, whatever - and xcode immediately lists them. The reason I have it within xcode, I can I copy the files into the executables directory by dragging the folder reference into a "Copy Files" build phase.
Thats basically (to my knowledge) how one uses the folder types within xcode - sadly, I don't know how to achieve the functionality you want. You may have to manually delete the folders in finder, which if you do use folder references will update xcode to the change.
I ran into the same issue by using "Create Folder References for any added folders". I wanted to change some of the times but that's not possible. I had added a main folder that had other directories under it. I just had to select the main directory and deleted it and then just add the subdirectories that I needed. You can't make any location or removal changes to the directories that are added this way. -- Jeff
In the project browser, where you're looking at files, right click and choose "Delete". It'll prompt you to either remove the file from the project (leaving the underlying file on the filesystem) or to also move the underlying file to the trash.
I ran into the same issue. Delete the files from the folder directly as opposed to from within Xcode. You'll see the entries turn red under your project. Restarting Xcode should make these red entries vanish.

How to quickly add back missing file in xcode

I zipped up my project folder in xcode and moved it to a new computer. When I open up the project it has missing files (file appears red).
How can I add all these files back or re-link them. It is like 20+ files?
Why didnt xcode store the relative path?
Xcode may not update location for some files of your project when you copy/move it from one environment to another. The easiest way I found is something like this:
1-Select your files like this, if they are in different groups, then repeat the flow on each group separately:
2- Show the file inspector:
3- You may notice Xcode has an absolute path for them, which is something not useful, so click on the little icon near Multiple Values. navigate to the folder where your selected files are stored in the finder and click "Choose".
Also, don't forget to change the Location to Relative to Project. Now you will get something like this:
• Select all the missing files that are in one folder in Finder.
• Change Location to Relative to Group ( that's in the File Inspector View -> Utilities -> Show File Inspector )
• Click the choose file button; it is under the Location drop down menu; it is an image that looks like a very small window with a document inside it.
A Choose folder containing the selected references sheet should appear.
• find and select the folder containing the missing files in the finder, then click Choose
(Tested in In xCode v4.3.2)
I normally keep all my files related to the project inside one folder (nested where necessary) and yeah I frequently exchange project files (zip and move) with my peers and nothing like that has ever happened to me.
You can always just drag the files en masse back onto the XCode window, and they'll get re-added. If you have file-system folders that match your Xcode internal organization that makes it even easier.
The UI has changed. In Xcode 10, there's a tiny dot with an arrow in it next to the file path. This does nothing as far as I can tell.
There's an obscure folder icon offset up and to the right of that non-functional arrow... this actually is a button, and it DOES allow you to relink the file.

Resources