Xcode will not open the ViewController.swift source files - xcode

I am in the Xcode editor. I can view the Main.storyboard or edit most of the source files. But for some reason the [*]ViewController.swift files will not display in the Editor section. What is going on?
The screenshot below shows that after hitting "enter" on the SecondViewController.swift instead of opening it in the editor the experiments.js remains. The same thing happens for SecondViewController.swift. However other .swift files do open properly.
I had edited those *Controller files in the past so this is bizarre. Any tips?

Observe how the icons are dimmed in the two ViewController files compared to experiments.swift
This usually means that the files are not where Xcode thinks they are. Check the path in the Document inspector and if needed use the widget in the inspector to correct the path or you can add the files again from their current location.
Maybe you moved the files outside of Xcode during organising or refactoring to cause this.

Related

View .svg files as text in Xcode?

I use xcode for my editing environment. I'm editing a few .svg files on a project, and I need xcode to open the files as text. Rather, it renders the documents as svg. While I appreciate how this helps most of the time (working and view svg's as such) its a hinderance to me right now.
Does anyone know how to tell xcode to treat a .svg file as regular text?
There is a simple way of changing the editor for any file type, particularly SVG in Xcode 5 (I believe this was possible in previous versions too):
Right click on the file in your Project Navigator, choose "Show File Inspector"
In File Inspector change the Type field to, for example, XML:
You will have to do it for each SVG file though. Seeing the graphical preview of your SVG is still possible via right click in Project Navigator -> Open As -> Preview.
In reply to mojuba and using the file inspector, I'm not sure this is what makes the difference but I have Location set to 'Relative to Workspace' (my workspace file and source files are in the same directory) and the settings do survive restarting Xcode. I'm using Xcode 4.2.1.
Renaming to .xml (make sure Finder isn't hiding the real extension by editing the name in the info panel) did work for me — in my case the SVG wasn't part of a project and so #mojumba's trick did not work.
It doesn't appear you can view source for .svg in Xcode, I'd suggest using something like vim or TextEdit.app, both of which are built-in to your system.

.xib files not showing up in MonoTouch

Right after building for the simulator I got an error message saying MonoTouch stopped unexpectedly and it shut down. So I closed Xcode and reloaded both. Now, I can't see my .xib files inside the MonoTouch file tree. I can open the .xib files directly in Xcode, but none of the resources need for the files are visible (for instance, images stored in the Resource folder).
How can I get these .xib files associated correctly again?
I fixed this. Had to go back and add each of my existing .xib files back into the project by right clicking on the appropriate folder and then finding the .xib file in the project folder. Once I added them all back, everything worked as expected

How do I correct the fact that my .h file is linking its IBOutlets to a XIB file from another project?

This is a real 'WTF?' moment for me.
I copied some classes out from another project, including copy and pasting the code and some UIBulder components. What did NOT get copied was the XIB file (I went from XIB to storyboard).
My tab / swipe recognizers aren't activating, and when I drill down the only thing I can discover that can explain it is that somehow, someway, I'm hooking up against the XIB file. (When I click on the little button next to the IBAction/IBOutlet lines in the header, it shows me both the storyboard and the xib file as connected).
I'm not referencing that file anywhere that I can find, it's just somehow magically recognized in Xcode. I don't know what to do, how to fix this.
Anyone have any ideas?
Edit: The really annoying bit is that the file doesn't appear to be in my files list when I check there, I can't just delete the reference that way. And since it's referencing the file in the original project, I can't just delete it. (Any changes made in either project cause changes in BOTH projects; their both using the same xib file for some reason). I should be able to simply delete the reference to the xib file, but I can't find the reference.
If you copy the view controller code from one project into another project you will notice a strange thing happening with the outlet. It is referencing the view from the first project without you ever connecting any outlets.
If you left click the little circle and click the reference link you will even be taken to the storyboard view in the other project. Trying to figure out how to get rid of this reference can drive you crazy.
Well, the good news is that there is really nothing for you to fix. You didn't copy over some deep, hard to find referencing link. Xcode is just getting confused because the View Controller and the outlet name are the same in both projects. Basically just ignore what that little circle says. You can close the first project and Xcode will figure things out eventually. Right click your views in the storyboard to see what referencing outlets really exist in the current project. (See my fuller answer for more details.)
No need to delete Derived Data. That doesn't solve the problem anyway. Just try opening both projects at the same time again and you will get the same strange behavior.
The way I figured this out was to separately create two new projects that had view controllers with the same name and a referencing outlet with the same name. I never copied anything but Xcode showed one was referencing the other. Like I said, ignore the little circle.
I just had the same problem. What solved it for me was to close both projects, delete the derived data from both and then reopen the destination project.
I agree, it's a crazy problem.
I'm sure that this problem could happen and I fix it deleting the content of the Derived data folder of XCode.
I just want to add the steps of how to delete those files:
Don't Delete the DerivedData folder.
Go to preferences (Command ,) > Locations Tab
On Derived Data you are going to see the path, clic the right pointing arrow (that will open that location in Finder)
Close XCode
Select all the files inside the DerivedData Folder (do NOT select parent folder) and (Command Delete) or move them to the Trash and then Empty Trash
Open the project and you are done
I hope it helps someone
unless the xib file is in the project. it should not have a link to it.
the xib file connects to the .h file. not the other way around.
You may want to remove the connections in the storyboard and re-connect them.
Also make sure that the storyboard is the UI being started and that the item on the navigation stack is actually the storyboard page. But you should be able to connect both the storyboard and the xib file to the class at the same time. You just cannot connect one IBOutlet to more than one object in a single ui component (e.g. two buttons on the storyboard cannot both be connected to #property IBOutlet UIButton *myCurrentButton you must have a separate IBOutlet for each connection. On the other hand, any number of actions can be connected to an IBAction. which is why you get (id) sender on each action.
I dont know if this is exactly what you are experiencing, but I hope that understanding helps you debug your issue.

XCode has lost associating from xib to .h file (MonoTouch)

When I am editing an XIB in XCode I don't get the associated .h file to show up in the assistant editor window. Other XIB's work fine.
This is a problem as it's the way I create outlets by dragging onto the assistant window. If I open the .h file manually in another window I can't associate an outlet this way either. The .h file exists.
Also, my project is MonoTouch and therefore I invoke the opening of the file from MonoTouch. I assume it's a problem originating in MonoTouch and not Xcode.
Someone please help, or I will be forced to learn Objective C soon and quit with this MonoTouch business.
Sometimes there is a different solution, such as when the controller file is RENAMED.
When this happens, edit the .XIB file with the Source Control Editor (right click on .xib, Open With->Source Control Editor), and make sure that all references to the name of the controller are correct and that the path and name of the .h file are correct.
Look in the "IBClassDescriber" element specifically. The "className" under the "IBPartialClassDescription" element and the "minorKey" under the "IBClassDescriptionSource" element must be correct. MT will generate a .h file with the same name as the controller.
After making the changes, save the file, choose Build->Clean All, then double-click the .XIB file to open it in XCode.
It may or may not work for you, but it worked for me when everything else failed.
As Stuart mentioned in his comment, deleting the /obj folder under the project which contains the .xib files, force MT to regenerate .h files
Came across the same issue and removing the /obj directory and restarting did the trick.
MonoDevelop 3.0.3.5 with XCode 4.4.
Was rather confusing as I am came across issue whilst on first MonoDevelop iOS Helloworld tutorial.
In my case, this issue has appeared when I change a namespace in .cs view controller file according to the file location. But after that, I caught this issue. When I have returned namespace to incorrect variant I got back my .h file.
Update:
You need to change the namespace in view.cs and in view.designer.cs, then Xcode .h file will be generated correctly.

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