Xcode 4 adding images to a project - xcode

Coming from a background of Visual Studio I had no idea how good that IDE truly was until I had to work with Xcode. One of the more pressing oddities that it has just thrown up is the following.
I'm upgrading a project to a retina display and so have to add a bunch of new #X2 files. This is fine, I have the files and I go into Xcode, choose the project group where I want to add them, select them all and click 'Add'.
"Multiple errors occured" Xcode helpfully blurts and then returns to whatever it was doing before. No break down of what those errors might be, or what actually happened or why.
So I do some looking and some of the files are actually in the directory but Xcode ignores them, I can't figure out a way of adding them (it says they're already there!) but they won't appear in the xcode project.
Can I 'refresh' xcode so it looks in the directory and shows them?
==============================
PS. While I'm here and can rant a little, anyone with a VS background now using Xcode, am I wrong in thinking the following points are hugely annoying:
1) The debugger - frustratingly slow.
2) The file explorer - can't easily sort by name
3) The file explorer - column on the right listing the file names doesn't change the file highlight when you move from file to file within the editor window.
4) Adding files to a project - see above!
Some of these probably stem from lack of experience with the IDE but still, they irk.

Files in the XCode directories don't necessarily have to be in the project.
For some reason, XCode doesn't like overwriting files, and that's the warning message that I usually get when this happens too - "Multiple errors occured."
What I suggest you do is remove all of the #2x files from your project directory, and add them back into XCode using "Add Files..." Make sure you select "Copy files into project directory if necessary" though, otherwise they will just be referenced to their current location on disk.

Related

Managing source files in Xcode

I was moving some files around in an Xcode project and deleted some files in finder (I know). I've broken my project and now I can't figure out how to fix it.
At the moment I'm getting an Undefined symbols for architecture x86_64: error when trying to build. The files however, are actually in the project and physically in the project directory. I added them to compiled sources, but I'm still getting the same error.
I don't understand how Xcode manages the source files and I haven't found any good information on how to troubleshoot these problems. Googling basically tells me to not delete files (too late) and I can't find anything in the Mac Developer documents.
How can I get my source files back in order so I can build this project?
EDIT: I noticed this in compiled sources:
The files that are causing the problems are the ones that don't have "...in Worker" next to them (Worker is the name of the project).
When you try to delete a file, then two options pop up: Remove reference or Move to trash.
If you select Remove reference, then you file is present in the project file directory. You just need to goto finder->your project and add that missing file.
If you select move to trash, then goto Trash, select file, right click and select put back.
If still you are getting error "Undefined symbols for architecture x86_64", then closely observe the error, in the last line of error, some variable name/class name is written there which is missing. Either that variable is declared multiple time or not declared.
I don't understand how Xcode manages the source files
It really doesn't. You add files to the project, and Xcode updates the project file with the fact that those files are in the project and their location on disk. If files go missing from the project (Xcode can't find them because you moved or deleted them), those file names are displayed in red in the project navigator.
So, start by looking for red filenames in the project navigator. Those are files you need to put back. If you're not sure where they were before, or if you want to move them to some other location, you can also just delete them from the project and then add them again.
At the moment I'm getting an Undefined symbols for architecture x86_64: error
That may mean that you've forgotten to add some file or other to a specific target. If you select a source file in the project navigator and look at the file inspector, there's a section called "Target Membership" where you can see which targets the file is part of. If you've just added a file to the project, make sure that the checkboxes next to all the targets that depend on that file are checked.
Go to "Build Phrases -> Copy Bundle Resources" and remove those files which are represented in Red color text.
Also make sure that in your project navigator you should remove those missing files as you deleted them physically from your project directory.
Hope this helps!

Multiple errors ocurred while copying files - but, can I see what they are?

There were around 200 files I had to delete in my Xcode project (and yeah, they were deleted properly), and now I have to copy 200+ files are supposedly replace the ones I just deleted.
I keep getting "Multiple errors occurred while copying files". The Xcode window doesn't show the newly-added files, but if I explore the project folder using the Finder, I can see that the files were indeed added - well, there most likely was a certain file that could not be copied and thus caused the error. Problem is, I have no idea which one nor why.
Now then, is it possible to get Xcode to tell me what the problem is rather than telling me there is one?
Edit: Okay, I did discover that some of the new files shared the same name as some files that were not listed in Xcode, which explains the error. However, I am still interested in knowing whether there is a way to know that the "Multiple errors" actually are whenever Xcode says t his.
When Xcode finds a duplicate file, it generates this error, and then it fails to add references for the files that it did manage to copy.
Rather than deleting files from the finder and starting over, you can do this:
Open the Finder for your project, where your source files are located
Command-click the ones for which your references are missing (and if you click others, it won't really matter)
Drag them into Xcode. When the confirmation dialog comes up, unset the "Copy items into destination group's folder (if needed)" checkbox. This will tell Xcode to make references only.
I deleted the files from finder and then added again the files via Xcode, that worked for me.
This error sometimes occurs when the code is not merged properly. The missing files will not be available in Xcode but once you open the finder containing this project, you will be able to spot the missing file.
The simplest way to add these missing files back to the project is:
1) In your Xcode, navigate to Build Phases Tab.
2) Under Compile Sources, tap on '+' to add back the missing file.
Sometimes the missing files will be greyed out in the build phases, just tap on '-' and add them back.
For me this is worked. I tried to add files which are already in my bundle. So make sure you are not adding files which are already added. I hope it helps someone.

How to stop Xcode from thinking files are missing

I deleted some files from my project (a pair of .m/.h).
However now every time I build Xcode warns that the files are missing (though the build is otherwise successful).
I can't see where/how Xcode thinks the files are needed, it must have some reference to them somewhere but I can't find it - the files are not listed in either the compile sources section nor the copy bundle resources section. Where else might they be listed such that Xcode feels the need to warn about them not being physically present?
To delete them try this:
create a file named like the missing one
copy this file into your project folder, so that Xcode recognizes it
right click on the file inside Xcode in the project view
select delete
select move to trash, when Xcode asks
This worked for me for files, however I have the same problem with empty folders. If somebody knows a way to get rid of the missing warning for them, please comment.
If the files are missing from the project navigator or your checkout, but not included in the build for the current target, then the build might succeed despite the warnings.
XCode's Project Navigator keeps track of files, the directory they're in, and the state in git or svn. The project warnings when opening a project are shown in the status view at the top of the window. You can review these warnings when you press command-4.
The project navigator marks files that it tracks, but that it cannot find, in red in the folder view (press command-1 for that view). If you see red file names it might be that you deleted or moved them into another folder without XCode knowing about that. Then select the red filename and delete it.
On top of this the files might be "missing from your work copy", but still present in the repository. You can do two things in the terminal to sync with or delete the file from subversion.
svn up file
svn rm --force file

ios file corruption

Ok so some how 2 of my classes had ended up in a weird directory
projectname>projectname.xcodeproj>
In my infinite wisdom I tried to transfer these to the proper directory were the rest of my classes are (projectname directory)
However now I cant compile due to it not being able to find certain files
what file can I edit to check to see where it's looking for these files?
UPDATE 1
in response to the first answer I have tried readding the files. which has netted me some different errors. Specifically that Cameleon-Prefix.pch, no matter how many times I re add it always shows red.
A quick fix for this is to delete the files from Xcode, but in the confirmation dialog, choose to just release the references. Then add the files again (from the File menu Add Files… item).
If you want to see where Xcode expects to find the files, choose the file in the navigator pane on the left, and set up the right hand pane with this configuration.
And from there you can click on the detail disclosure buttons to see even more.
Edited to add
Make sure this is the same file pointed to in your build settings:
Do a similar search for pch to make sure the same thing goes with the pch file

xcode copying project to another computer

I'm having problems copying a project over from one mac to another. The project compiles and runs fine after being copied, however xcode seems to have some duplicate of the same classes which seem to be invisible on the project browser on the left.
For example if I jump to definition on a variable I get 2 suggestions pop up. The top file when I look at its properties is relative to xcode folder (this is also the one that shows up in the class browser to the left). The second file which cant be seen on the browser has absolute path type in the properties.
Is there any way to get rid of this behaviour so its just looking at one file only like it originally was doing on the other mac? Its a bit problematic as I am never sure which one I am editing and they don't seem to update each other even though they appear to be the same file.
On a side note if I copy the copied project to another location then I get 3 etc files pop up in the jump to definition.
It's usually a good idea to either not copy the "build" folder (or delete it after you've copied everything over - only do this when Xcode is not running though).
Ok so what you need to do is this:
1.Duplicate your project.
2.Open the copy w/the original ,but only the folder.
3.open the Projects files(not the tests the main files)
4.then Drag and drop the files into the xcode area.
5.Zip the folder and its done
its like that because it just removes the references but not the files they are all still there though so just add the references back into the file.

Resources