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

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:

  1. Add "New OS X Icon" to images.xcassets and name it "DocIcon", for instance.
  2. Drag and drop images of your document icon
  3. 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):

  1. Select asset catalog in Project Navigator
  2. 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.
  3. 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).
  4. 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...).

  5. Copy the newly created Document.icns file as a resource to your project.

  6. 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.

Tags:

Macos

Cocoa

Xcode