Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Created March 3, 2021 18:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sindresorhus/490c38e3d6d238e6a063e556c41053d2 to your computer and use it in GitHub Desktop.
Save sindresorhus/490c38e3d6d238e6a063e556c41053d2 to your computer and use it in GitHub Desktop.
extension Image {
/**
```
Image(nsImageNamed: NSImage.addTemplateName)
```
- Note: The `size` parameter is there as resizing in SwiftUI creates a blurry image. Seems like a bug:
```
Image(nsImageNamed: NSImage.addTemplateName)
.resizable()
.frame(width: 100, height: 100)
```
*/
init(nsImageNamed: NSImage.Name, size: CGSize? = nil) {
let image = NSImage(named: nsImageNamed)!
if let size = size {
image.size = size
}
self.init(nsImage: image)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment