Reputation: 638
I'm currently doing it this way but I have to save it twice before the icon shows on the file:
override func save(to url: URL, ofType typeName: String, for saveOperation: NSSaveOperationType, completionHandler: @escaping (Error?) -> Void) {
NSWorkspace.shared().setIcon(NSApp.applicationIconImage, forFile: url.path, options: NSWorkspaceIconCreationOptions(rawValue: 0))
super.save(to: url, ofType: typeName, for: saveOperation, completionHandler: completionHandler)
}
How can I set the icon for my file extension as soon as its being saved?
Upvotes: 2
Views: 175
Reputation: 5698
So I'm not 100% if I'm missing something else here, but we do this, and it looks like all you need to do is modify your info.plist
with this row:
Unfortunately the dev that originally implemented this did so 8 years ago and is long gone, so I can't confirm if there are other steps you need to take. Let me know if it doesn't work and I can dig around for you some more
EDIT: Apple documentation on Document Icons
Upvotes: 1