3

According to documentation doing:

let alert = NSAlert() 
alert.icon = nil
alert.runModally()

should render application's icon. But I get placeholder instead.

enter image description here

zuziaka
  • 575
  • 3
  • 10

2 Answers2

2

Was just having this same problem. Initially I had only a 256@1x icon and got no icon in the alert. Once I added a 128@1x icon to the AppIcon resource however, the NSAlert displayed it properly.

And no, you don't need to explicitly set the icon to nil.

gmw
  • 417
  • 3
  • 15
  • Do the icon files need to be named like that? i.e. "128@1x.png"? Mine are currently like "128x128@1x.png" but I'm getting the placeholder in my alerts... – alesplin Sep 08 '18 at 07:38
0

You can tried some apple built-in icons such as:

alert.icon = NSImage (named: NSImage.cautionName)

Full list of apple icons is here: https://developer.apple.com/documentation/appkit/nsimage/name

Sai Zhou
  • 71
  • 3