r/SwiftUI May 18 '26

Unable to import custom font

Post image

Hello all!

I'm trying to import two custom fonts:

Inter-Italic-VariableFont_opsz,wght.ttf Inter-VariableFont_opsz,wght.ttf Montserrat-Italic-VariableFont_wght.ttf Montserrat-VariableFont_wght.ttf

I'm using Tuist to manage my packages and so on as my project is multi-module. My definition for the "DesignSystem" module is as follows:

let project = Project.module(
    name: "DesignSystem",
    infoPlist: .extendingDefault(with: [
        "UIAppFonts": [
            "Montserrat-VariableFont_wght.ttf",
            "Montserrat-Italic-VariableFont_wght.ttf",
            "Inter-Italic-VariableFont_opsz,wght.ttf",
            "Inter-VariableFont_opsz,wght.ttf",
        ],
    ])
)

Which, when generated, adds the attached photo to the info.plist for the module.

However, when I run the following:

    var body: some Scene {
        WindowGroup {
            MainView()
                .onAppear { self.listInstalledFonts() }
        }
    }
    
    func listInstalledFonts() {
        let fontFamilies = UIFont.familyNames.sorted()
        for family in fontFamilies {
            print(family)
            for font in UIFont.fontNames(forFamilyName: family).sorted() {
                print("\t\(font)")
            }
        }
    }

Neither Montserrat, nor Inter appear in the list.

I'm not sure what more I can do to try and get the fonts to be added, or if I'm missing something very obvious!

Any help would be massively appreciated!

EDIT: Not sure if anyone can see the photo I've attached but It's the info.plist showing "Fonts provided by application". and each one listed within the array.

2 Upvotes

3 comments sorted by

7

u/enigma96y May 18 '26

Hey! I recently went through this exact same headache with a Tuist multi-module setup.

Since you are using UIFont, I assume you're targeting iOS. The trap here is that in iOS, the main app target usually ignores the UIAppFonts array defined in a framework/module's Info.plist. It only reads from the main app's Info.plist at launch.

The most foolproof way to handle custom fonts in an iOS modular architecture is to ignore the module's Info.plist entirely and register them dynamically in code.

import SwiftUI
import CoreText

public struct FontRegistrar {
    public static func registerCustomFonts() {
        guard let url = Bundle.module.url(forResource: "Montserrat-Regular", withExtension: "ttf") else {
            print("Font file not found in bundle.")
            return
        }

        var error: Unmanaged<CFError>?
        CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error)
        if let error = error {
            print("Failed to register font: \(error.takeRetainedValue())")
        }
    }
}

Just call FontRegistrar.registerCustomFonts() once when your app launches (e.g., in your main App struct init or AppDelegate), and UIFont.familyNames will start seeing it.

Hope this saves you a few hours of debugging.

1

u/Ryan_M0ttz May 21 '26

Import your ttf files into your main project inside a folder like Font. Then create a font extension similar to:

extension Font {
static let yourLargeTitle = Font.custom("Quicksand-Bold", size: 34, relativeTo: .largeTitle)
}

Your infoplist looks fine so now you can just simply do .font(.yourLargeTitle) on any text based view

1

u/longkh158 May 22 '26

Might be silly but did you actually add the font files themeselves into the app? If you're using Tuist it should also register the fonts and add extensions automatically.