How to use custom fonts in Swift Playgrounds 4.2.1 (.swiftpm app playground project)?

I have done plenty of research, and I am aware of this post on the same exact question, and I tried that exact solution. However, it will not work as it throws the fatal error, "Couldn't create font from data". It seems like Swift cannot find my font.

I am currently using Xcode to create a SwiftUI project in an app playground (.swiftpm) file. This file can then be moved over to the MacOS Playgrounds app or iPadOS Playgrounds app etc. I found a custom .otf font that I want to use for my project, but I am having trouble using it.

If you have any experience with these, you would know that .swiftpm Playgrounds lack Info.plist files, so you cannot simply do what you would do in an Xcode project to use custom fonts (which involve a .plist).

How can I do this? I would really like to have a solution in SwiftUI, and I really wished that the linked solution would work as it seems like a great solution. My only thought now is that I am putting the fonts in the wrong directory, as .swiftpm files do not come with a Resources folder, unlike an older macOS .playground file, for example. I will attach a picture of my file structure here if that is helpful. I definitely know that the official PostScript name of my files match the names of the font variations in the screenshot (I double checked in Mac's FontBook). I have been trying to fix this for long enough to know that I definitely am not spelling anything wrong and I know that the file is definitely not corrupt because I can use it in other softwares and I got it from a reliable source.

If anyone knows how to do this, I would really appreciate your help. Feel free to look at the previous solution I was looking at linked above. Thanks! :)

As an additional note, the Font.swift file is completely empty, so you aren't missing anything from not seeing that. And yes, I have tried moving where the fonts are to many, many places, including the Assets.xcassets folder. Nothing has worked so far.

Post not yet marked as solved Up vote post of JoeN Down vote post of JoeN
1.5k views

Replies

I'm also trying very hard to make the custom font work.

Have you found any work around? I've found out that the link you have provided is from someone that following an instruction from https://www.jacobzivandesign.com/technology/custom-fonts-from-swift-package/