Using an icon set for Mac document icon

I'm trying to add a document icon for my Mac application. I created an icon set for the document icon. In Xcode (I'm using Xcode 7.3.1) I select the Images.xcassets folder. I click the Add button and choose App Icons & Launch Images > New OS X Generic Icon. I drag the various image files from the icon set to the appropriate image wells. I name the icon DocumentIcon.


Now I go to the project editor and go to the document type. I enter the name DocumentIcon in the Icon combo box. Instead of showing my icon image, Xcode shows a question mark. When I run the application and save a document, the document has the generic document icon. Cleaning and rebuilding the project has no effect.


I searched online for possible solutions, but they predate the use of icon sets. What do I have to do to use the icon set I created as the document's icon?

Replies

Is your document type using an exported (or imported) UTI? If so, you need to say which icon to use in the export (or import) declaration, not the document type.


It's not unusual for the document type to show up as a question mark in the Xcode UI, not sure why, but I wouldn't necessarily assign much significance to that.


Also, if you have a previously built copy of the app anywhere on your disk(s), it's unpredictable which copy will be chose to provide the document icons. You might have to search-and-destroy the old ones.


You can also try looking in the (recently) built app to see whether the icon file is there, and whether the info.plist has the correct name for it.

>Cleaning and rebuilding the project has no effect.

Right...booo, hiss.

Instead of just a simple (single target) clean, use Xcode's Product menu, then, with the option key pressed, select 'Clean Build Folder'. Confirm no errors in the navigator and go again.

My document type is not using an exported or imported UTI. The icon file is in the Resources folder of the app bundle.


In the Info.plist file I tried using the icon filenames DocumentIcon and DocumentIcon.icns. I cleaned the build folder with both filenames and rebuilt the project. I still get the generic document icon.

>icon filenames DocumentIcon and DocumentIcon.icns

Did you rename the icons after adding them to the project or otherwise juggle them in the Finder, outside of the project?

Going back to what you said originally "I drag the various image files from the icon set to the appropriate image wells. I name the icon DocumentIcon."

...in that order? Dragm then (re)name? If so, I would remove them from the project, option-clean, confirm their names in the Finder first, then add them to the project/asset catalog without any name changes, then build again.

Assets catalogs have sometimes felt brittle to me. You might have to avoid them and just manually deal with your icons in the project.