/
Font.swift
33 lines (30 loc) 路 995 Bytes
/
Font.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#if canImport(UIKit)
import UIKit
/// Extension on UIFont providing a method to retrieve all available font names.
public extension UIFont {
/// Returns an array containing all available font names.
///
/// Font names are sorted alphabetically, with variations grouped under their family names.
///
/// - Returns: An array of all available font names.
static func allFontNames() -> [String] {
familyNames.sorted()
.map { UIFont.fontNames(forFamilyName: $0).sorted() }
.flatMap { $0 }
}
}
#endif
#if canImport(AppKit)
import AppKit
/// Extension on NSFont providing a method to retrieve all available font names.
public extension NSFont {
/// Returns an array containing all available font names.
///
/// Font names are sorted alphabetically.
///
/// - Returns: An array of all available font names.
static func allFontNames() -> [String] {
NSFontManager.shared.availableFonts.sorted()
}
}
#endif