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

With iOS 13 and macOS 10.15 Apple made the new system fonts, including SF Mono and New York, available for developers.

You can get SF Mono using NSFont.monospacedSystemFont(ofSize: 0, weight: .regular).

Alternatively if you want to use the other system fonts you can use the NSFontDescriptor:

if let sfMonoDescriptor = NSFont.systemFont(ofSize: 0).fontDescriptor.withDesign(.monospaced) {
    let sfMonoFont = NSFont(descriptor: sfMonoDescriptor, size: 0)!
}

For more information look at the WWDC Session Font Management and Text Scaling.


"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)

Tags:

Swift

Nsfont