swiftnsfont

What is the NSFont name for the font 'SF Mono'?


A new font titled 'SF Mono' was introduced with Xcode 8.

It's a font that I personally find very readable, and I would like to use it in a NSTextView. However, to set a font for an NSTextView, it is required to use an NSFont object. The problem is that I cannot seem to find the SF Mono font in the list of available fonts through NSFontManager.shared().availableFonts.

Does anyone know what the SF Mono's programmatic name is for the initialisation of an NSFont (NSFont(name: String, size: CGFloat)) for its typeface?


Solution

  • "SF Mono" is not a system font. You cannot select SF Mono outside of Terminal, Console and Xcode because it is not installed to the system.

    The "SF Mono" in Terminal is a custom font in /Applications/Utilities/Terminal.app/Contents/Resources/Fonts/.

    Similarly, the "SF Mono" in Console is another custom font in /Applications/Utilities/Console.app/Contents/Resources/Fonts.

    Similarly, the "SF Mono" in Xcode is also a custom font in /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/.

    And of course you cannot bundle SF Mono alongside your program without violating Apple's copyright license:

    This SF Mono Font (the “Apple Font”) is licensed to you by Apple Inc. (“Apple”) in consideration of your agreement to the following terms. If you do not agree with these terms, do not use the Apple Font.

    You may use the Apple Font solely in conjunction with Apple-branded applications, including, but not limited to, Xcode, Terminal.app and Console.app. You may not embed or use the Apple Font in or with any other software applications or programs or other products and you may not use the Apple Font to create, develop, display or otherwise distribute any content, documentation, artwork or any other work product.

    You may use the Apple Font only for the purposes described in this License or as otherwise expressly permitted by Apple in writing.

    If the user has manually installed the font, it can be found with family name SF Mono, or the font name SFMono-Regular (similar for the other weights).

    let f = NSFont(name: "SFMono-Regular", size: 12)