FontAwesome.swift icon indicating copy to clipboard operation
FontAwesome.swift copied to clipboard

Swift Package Manager

Open matt-matt1 opened this issue 4 years ago • 15 comments

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?

matt-matt1 avatar Feb 19 '20 17:02 matt-matt1

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 avatar Mar 22 '20 01:03 DerekK19

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

DerekK19 avatar Mar 23 '20 03:03 DerekK19

I didn't manage to make it work using SPM

dneykov avatar Apr 03 '20 07:04 dneykov

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

DerekK19 avatar Apr 12 '20 04:04 DerekK19

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

MatrixSenpai avatar Apr 29 '20 02:04 MatrixSenpai

@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 avatar May 04 '21 06:05 AkashlalBol

@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

MatrixSenpai avatar May 04 '21 22:05 MatrixSenpai

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 avatar May 05 '21 06:05 AkashlalBol

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

MatrixSenpai avatar May 12 '21 21:05 MatrixSenpai

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 avatar Aug 21 '21 16:08 phoney

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.

phoney avatar Aug 27 '21 14:08 phoney

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

CC: @AkashlalBol

sandeepbol avatar Jan 05 '22 12:01 sandeepbol

I can confirm SPM works using @sandeepbol fork.

Great job. Thanks!

dneykov avatar Jan 25 '22 12:01 dneykov

@MatrixSenpai Please close after creating the tag.

sandeepbol avatar Jan 31 '22 04:01 sandeepbol

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.

cfoughty7 avatar Feb 27 '23 16:02 cfoughty7