20

SF Symbols provides a set of over 2,400 consistent, highly configurable symbols you can use in your app. Apple designed SF Symbols to integrate seamlessly with the San Francisco system font, so the symbols automatically ensure optical vertical alignment with text in all weights and sizes.

https://developer.apple.com/design/human-interface-guidelines/sf-symbols/overview/

As far as I can see, macOS does not support NSImage(systemName: String) syntax when trying to use SF Symbols in a macOS project.

To be specific, I was trying to use an SF Symbol glyph on a toolbar item.

marc-medley
  • 8,931
  • 5
  • 60
  • 66
fankibiber
  • 729
  • 1
  • 6
  • 19
  • Is there a reason you wish to use `NSImage` instead of `Image`? After all, you're using `SwiftUI`. –  Sep 24 '19 at 14:36
  • 1
    It doesn't matter whether he wants to use `Image` or `NSImage`, because neither supports the `init(systemName:)` initializer on macOS. – rob mayoff Sep 24 '19 at 15:55

7 Answers7

20

SF Symbol are now available with macOS 11.

SF Symbols are available in iOS 13 and later, macOS 11 and later, watchOS 6 and later, and tvOS 13 and later.

Here is how you use it:

NSImage(systemSymbolName: "hammer", accessibilityDescription: nil)

If you want to support macOS 10.15 and below you have to use the SF Symbols Mac app and export the symbol as SVG and import it back to an asset file in your Xcode project. You can get the app from here.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Daniel
  • 1,473
  • 3
  • 33
  • 63
  • Why does Xcode not recognize this initializer when I try to use it? – Peter Schorn Nov 19 '20 at 06:52
  • I'm on Xcode 12.1 and macOS 11. I'm guessing that I need Xcode 12.2 or 12.3. What version are you on? – Peter Schorn Nov 19 '20 at 07:25
  • 2
    After updating to Xcode 12.2, the symbol showed up. That's the minimum version for this API. – Peter Schorn Nov 26 '20 at 08:38
  • Compiling for macOS 11.1, Xcode wouldn't complete systemSymbolName for me. I used `NSImage *image = [NSImage imageWithSystemSymbolName:@"hammer" accessibilityDescription:nil];` (maybe I had the wrong objc syntax since once is a [type method](https://developer.apple.com/documentation/appkit/nsimage/3622472-imagewithsystemsymbolname) and the other an [initializer](https://developer.apple.com/documentation/appkit/nsimage/3622472-init)). – idbrii Feb 18 '21 at 23:27
  • It's giving a bad example when giving `nil` to the `accessibilityDescription:` argument! People blindly copy/paste this. In order to support people with vision impairements, you should pass a useful (and localized) text that users can read with VoiceOver! – Thomas Tempelmann Aug 31 '21 at 15:49
14

SF Symbols is not supported on macOS (yet)

But you can download the SF Symbols App and export the symbols you need as stand-alone images.

vadian
  • 274,689
  • 30
  • 353
  • 361
2

SF Symbols are unavailable on macOS. From Apple's Human Interface Guidelines:

You can use SF Symbols in apps running in iOS 13 and later, watchOS 6 and later, and tvOS 13 and later.

LuLuGaGa
  • 13,089
  • 6
  • 49
  • 57
0

There is no way yet to use SF symbols on macOS. However you can use this extension as a fall back on macOS so your code will run on multiple platforms.

extension Image {
    init(systemName: String) {
        self.init("YOUR FALL BACK IMAGE(s)")
    }
}
MetaImi
  • 274
  • 2
  • 13
0

You could also export the symbol from SF Symbols app into SVG and convert them into SwiftUI Shape using this tool: quassummanus.github.io/SVG-to-SwiftUI/

0

If your macOS version is below macOS 11.

  1. Download sfsymbols and export all of symbols https://github.com/davedelong/sfsymbols

  2. Select Assets.xcassets in your Xcode project

  3. Drag an iconset folder as new asset to your Assets.xcassets in Xcode enter image description here

webcpu
  • 3,174
  • 2
  • 24
  • 17
-4

Important Before use code bellow read this article How to support San Francisco Fonts on old iOS app and macOS

Button(action: {}) {
  Image(systemName: "star")            
}
I make Image for macOS like below

enter image description here

that's how it looks on macOS

enter image description here

And for cut/paste:

import SwiftUI

#if os(macOS)
struct Image: View {
  let symbol: String

  init(systemName: String) {
    self.symbol = [
      "speaker":      "",
      "speaker.fill": "",
      "star":         "☆",
      "star.fill":    "★"
      ][systemName] ?? "?"   }

  var body: some View {
    Text(symbol)
  }
}
#endif
Victor Kushnerov
  • 3,706
  • 27
  • 56