Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Package Manager #248

Open
matt-matt1 opened this issue Feb 19, 2020 · 15 comments
Open

Swift Package Manager #248

matt-matt1 opened this issue Feb 19, 2020 · 15 comments

Comments

@matt-matt1
Copy link

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?

@DerekK19
Copy link

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

@DerekK19
Copy link

DerekK19 commented Mar 23, 2020

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

@dneykov
Copy link

dneykov commented Apr 3, 2020

I didn't manage to make it work using SPM

@DerekK19
Copy link

DerekK19 commented Apr 12, 2020

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

@MatrixSenpai
Copy link
Collaborator

Hey Matt! This will be addressed in the next major version. I'm adding this to our project board now

@AkashlalBol
Copy link

@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.

@MatrixSenpai
Copy link
Collaborator

@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

@AkashlalBol
Copy link

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.

@MatrixSenpai
Copy link
Collaborator

@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.

@phoney
Copy link

phoney commented Aug 21, 2021

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?

@phoney
Copy link

phoney commented Aug 27, 2021

I've made a PR with updated SPM support that includes copying the font files into your project. #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.

@sandeepbol
Copy link
Contributor

You can use our fork for the SPM crash fix -- https://github.com/BankofLoyal/FontAwesome.swift

CC: @AkashlalBol

@dneykov
Copy link

dneykov commented Jan 25, 2022

I can confirm SPM works using @sandeepbol fork.

Great job. Thanks!

@sandeepbol
Copy link
Contributor

@MatrixSenpai Please close after creating the tag.

@cfoughty7
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants