View .svg files as text in Xcode? - 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.

Related

Xcode will not open the ViewController.swift source files

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.

Copy file full path in Xcode

I'm using Perforce for managing our code base. In Perforce, we need to check out a file before we can edit it. When I'm working in Xcode, sometimes I want to know the full path to the working file so that I can check it out in Perforce.
So here is my question:
Is there a shortcut, plugin or some other quick way to copy the full path of a file in Xcode?
What I have known:
I can Command+click on the file tile to show up the full path, but I cannot copy it.
In Visual Studio, we can right click on the file's tab and choose Copy Full Path to achieve this.
In Eclipse, we can Alt/Option + Enter to achieve this.
Update:
Actually my question is about how to achieve the equivalent Copy Full Path feature inside Xcode. Anyway, dragging the file to the terminal is also a very nice workaround.
You can copy it directly out of the File Inspector. The first section ("Identity and Type") of the File Inspector shows information about the selected file, or the file that contains the selected symbol, etc. You have Name, Type, Location, and Full Path. You can select the full path and copy it.
As a shortcut, a triple click on any part of the path will select the entire path. There's also a small icon with a light arrow on a dark background -- clicking that will open a Finder window with the file selected.
You can drag it to a terminal... Easy and fast...
on your editor XCode (you want to get the file path). Press:
Command+Shift+J
xcode will open directory file path on Project Navigator (left side bar)
and then drag-and-drop file from Project Navigator to the terminal. it will give you the directory of the file.
You can use find command to copy file path:
cd myProject
find . -name myCodeFile.cpp
Extending Caleb's answer, here is a graphical demo:
Steps:
Select a filename on the Project navigator from the left side Navigator panel.
Tap on Show File Inspector from the right side Inspectors panel. (marked with red box)
Copy the path from there. (marked with a bigger red box)

Cocoa: Localize Dialog

I'm currently translating my application (Mac OS X app) into another language. I've done almost all translations, but now I'm stuck on a pretty strange thing:
I have an additional window for the applications settings and translated the GUI elements the same way I did it for the main window. I imported the translations into my project which seemed to work fine because I can use the preview windows, switch the language of the assistant editor to German and see that the dialog will be localized correctly.
But as soon as I run my application (with "German" as language) and open the settings dialog the whole dialog is still in English (the base language).
The settings dialog's XIB file is located in the base.lproj folder and the corresponding .strings file is located in the de.lproj folder (which should be correct as the preview shows the correct translations).
I don't know what's going on and have no clue what might be the issue.
Does someone have any clue?
I'm using Xcode 6.1.1
I found the reason for this issue: Localizing the settings dialog forced Xcode to move it into the Base.lproj folder. But instead of moving the file Xcode just copied it into that folder - so the XIB file for the dialog existed twice and Cocoa used the old one (which was not localized).
After cleaning the build directory and deleting the derived data for the project the localization works fine now.

How do I access images (for document icons) in an asset catalog in the Xcode 5 product preference editor

I think I'm literally on the last step before submitting a new Mac app, and I've been banging my head against a wall for the past few hours on what I think should be really, really easy.
I've designed document icons for the two different types of icons my app creates and works with. I created a new "Icon" in Images.xcassets, and dropped the appropriate files into the drop zones.
In the product editor -> Info, I go to where the document type information is, but when I try to enter in the icon name in the "icon" field of either the Document Types or Exported UTI section, the icon image just turns into a question mark—no options show up in the drop down menus for icons.
How do I get the images/icons in the asset catalog to show up in the editor? Alternatively, if I was going to enter that manually into the plist, what sort of format would I use to reference an Icon file from the asset catalog?
I know I'm probably missing an easy step here, but I can't see it!
To my knowledge, Xcode doesn't currently support using .xcassets for document icons. This is a little strange—the .xcassets editor clearly allows you to create new icons, but it doesn't generate .icns files, it just puts all the files in the same folder and uses a plist to manage them.
To create an icon for your document types, upload the 1024x1024 version of the icon to http://iconverticons.com/online/ to convert it to a .icns file. Alternatively, you could use a third-party tool to generate an .icns file with different images for different resolutions. There used to be a great tool included in the Developer Tools for doing this, but I can't seem to find it anymore.
Once you've got an icns file, add it to your project and you should be able to select it as the "Icon" for your Document Type or External/Internal UTI. Enjoy!
To be honest, it might be worth filing a bug about this. Xcode's development seems so strongly driven by iOS these days, they may not have noticed this yet!
I did it in the most easy way:
Add "New OS X Icon" to images.xcassets and name it "DocIcon", for instance.
Drag and drop images of your document icon
Just type "DocIcon" to icon name of your document
You will see question mark as document icon thumbnail. Don't care about. All will work fine after build and launch of application.
This is what worked for me, using Xcode 10 in 2019 (none of the other answers worked in my case):
Select asset catalog in Project Navigator
Right click on the left pane (list of assets) and choose App Icons & Launch Images ▶︎ New macOS Generic Icon (second option from bottom). Name it "Document". This will create a folder named "Document.iconset" in the asset catalog directory.
Populate all entries with your custom images. They must all be of the appropriate size (e.g., "16 x 16 #2x" must be 32 x 32 pixels, otherwise you will get yellow a warning icon over the image slot).
Navigate to the asset catalog folder, and use the command: iconutil -c icns Document.iconset (must match the name of the icon created in step #2). I took this command from Apple's documentation here (which by the way, also says some BS about Xcode "automatically creating an .icns file from your .iconset folder on build". Sure...).
Copy the newly created Document.icns file as a resource to your project.
Select the target, open the Info pane, and in both Document Types and Exported UTIs set your .icns file as the icon for the file type.
Hej, allesamme,
I had the same problem and have been researching it for days. I found a family of four solutions, the first three of which did not work for me: 1. using a .png file as the document type icon file; 2. using a manually created .icns file as the document type icon file; 3. the above solution, and 4. what I will describe here. Only the last one worked for me.
I tried following the spirit of the above advice and found that it didn't work, at least for my MacOS app. I'm on OS X 10.9.2 (13C64) running Xcode Version 5.1 (5B130a).
The current wisdom seems to be to create a directory in your workspace with a lower-case name and .iconset extension, in which one puts files with an icon_ prefix and the usual suffixes (16x16.png, 16x16#2x.png, 32x32.png, etc.)
In Product Editor's Info pane you can go into Document Types and associate the .iconset file with the Icon field. The icon image happily displays something reasonable. The build process builds a .icns file from that spec and copies it into your app.
I had an intermittent problem that the .icns file wouldn't build, which I traced to mistakenly haven included a 64x64 icon in the list. That's a no-no.
The current Apple dogma on this issue can be found in the official documentation, which covers some details I glossed over here. I didn't need to edit the Info.plist file directly: everything seemed to work from the interfaces provided in Xcode.
I have no idea which solutions work in which contexts, but thought I'd add throw more alternative on the fire for people to try out. — Jim Coplien

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