11

I would like to use SF Symbols in my macOS project. How to implement one?

Button(action: {}) {
  Image(systemName: "star") //Error: 'init(systemName:)' is unavailable in macOS            
}
Victor Kushnerov
  • 3,706
  • 27
  • 56

3 Answers3

6

It is nativly supporting from the macOS 11 beta or later, then it works as usual, otherwise you have to export a template and import it to the assets catalog, then you can use it as a normal image. So:

if #available(OSX 11.0, *) {
    Image(systemName: "trash.fill")
} else {
    Image("trash.fill") // Imported as a supporting format like PDF (not SVG)
}

Another way is to use the symbol directly in the text:

Text("") // The symbol itself can not be shown on the markdown of the StackOverflow

Demo

Remember that you should embed the font in your application or the destination should have the SF Symbols App installed

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
3

Apple's Human Interface Guidelines state:

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

No Mac support at this time. ☹️

John M.
  • 8,892
  • 4
  • 31
  • 42
  • I updated my question adding my solution to this issue. Perhaps you have comments. – Victor Kushnerov Sep 30 '19 at 18:28
  • I suppose that works if you only have a few icons. Not sure if it would render on a machine that doesn't have SF Symbols installed, and no idea about the licensing ramifications. – John M. Sep 30 '19 at 18:43
-1

Before using this code you should install SF Symbols app

I make Image for macOS like below

enter image description here

that's how it looks on macOS

enter image description here

Victor Kushnerov
  • 3,706
  • 27
  • 56
  • 2
    This will not work in computers that don't have the SF Symbols font installed. – Nick Keets Oct 31 '19 at 13:25
  • Install SF Symbols for Mac from [here](https://developer.apple.com/design/downloads/SF-Symbols.dmg) – Victor Kushnerov Oct 31 '19 at 13:44
  • 2
    Sure, what about the users of your app though? Are you going to tell all of them to do that? Is that even going to pass app review at the App Store? – Nick Keets Nov 01 '19 at 07:06
  • 1
    If you don't want to force users to install sf symbols app I can offer such a way to implement used icons like pdf icons by [this app](https://github.com/davedelong/sfsymbols). A question of approving in App Store you can ask on Apple forum and notify me, I will add theirs answer. – Victor Kushnerov Nov 01 '19 at 07:22
  • Sample code how to use sf symbols pdf icons [here](https://github.com/filimo/ReaderTranslator/blob/master/ReaderTranslator/Extentions/Image.swift) – Victor Kushnerov Nov 01 '19 at 07:30