Open matt-matt1 opened 4 years ago
My own experience is that it cannot. There is a package.swift file in the project, and I added this package to my own project. However when I ran the app, I got a crash on line 94 of FontAwesome.swift - return UIFont(name: style.fontName(), size: fontSize)! I assume that the font otf files themselves are not being loaded through the package manager. I have switched back to using Carthage for this dependency in my project and now I do get the fonts I was expecting
Further to my reply, I have now figured out how to get FontAwesome working. Include the package as you would any other, but manually copy the 3 otf font files into your project - I copied them to the same folder as my storyboard and other assets
I didn't manage to make it work using SPM
Did you follow my instructions. Just add as you would any other SPM package. However you must manually copy the 3 font files into your project - I put them in my Resources folder. The files are named Font Awesome 5 Free-Regular-400.otf, and another two with similar names. Also make sure to set the Target Membership flag for your target. That's all I did and I have FontAwesome fonts in my app. Apparently there will be a fix for SPM in Swift 5.3 later this year; this should allow the fonts to be included in the package
There is one issue however when you're running a Mac-Catalyst app. It occurs if you use more than 1 FontAwesome font in your app. I have raised an issue for this
Hey Matt! This will be addressed in the next major version. I'm adding this to our project board now
@DerekK19 Thanks for your input. FontAwesome Swift library surprisingly still has this issue.. Importing the 3 otf font files resolved the issue for me as well.
@AkashlalBol there's some difficulty with resources in SPM
SPM only recently added the ability to include resources with a package, and loading from those needs to be handled separately from CP and normally loaded bundles. All of this is being re-written
Okay @MatrixSenpai, makes sense :) However good for this information to be added to readme.md file, because current FA is SPM compatible after importing the 3 font styles separately.
@AkashlalBol if you load the fonts yourself, there is no incompatibility. If there is, please post an error log. However, this code is responsible for pre-checking if the font has already been loaded by the system. To assist with this, I recommend using FontBlaster, which I use for more than just FontAwesome.
SPM was updated last year to support Resources in swift 5.3, Xcode 12. This page https://developer.apple.com/documentation/swift_packages/bundling_resources_with_a_swift_package says that setting the swift tools version to 5.3 should make resources "just work." Any progress on this?
I've made a PR with updated SPM support that includes copying the font files into your project. https://github.com/thii/FontAwesome.swift/pull/272 I invite anyone that wants to use SPM to try the PR and then review it. You should remove the font files from your project if you do test it to make sure they're being copied by SPM.
You can use our fork for the SPM crash fix -- https://github.com/BankofLoyal/FontAwesome.swift
CC: @AkashlalBol
I can confirm SPM works using @sandeepbol fork.
Great job. Thanks!
@MatrixSenpai Please close after creating the tag.
Is there an issue w/ loading fonts when the package is installed via SPM for version 1.9.1
? I have no issue when using fonts with the solid
style, but when I try to use the regular
style the package fails to find that font in the bundle, even though I can see it is clearly there in the package with the correct name.
Can this be used in Xcode as a Swift Package dependancy?
If so, Is this better than using CocoaPods?
If so, any other files needed?