SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.3k stars 742 forks source link

Add preliminary support for Swift Package Manager #395

Closed knothed closed 4 years ago

knothed commented 4 years ago

Since SPM came around, people wanted SwiftMessages to be compatible with SPM (https://github.com/SwiftKickMobile/SwiftMessages/issues/330, https://github.com/SwiftKickMobile/SwiftMessages/issues/362, https://github.com/SwiftKickMobile/SwiftMessages/issues/387). Sadly, SPM currently has no support for resource bundling – however, with Swift 5.3, this will finally change.

This pull request accomplishes two things:

  1. Add preliminary support for SPM until Swift 5.3 officially appears
  2. Prepare SwiftMessages for upcoming Swift 5.3 SPM support by adding a Package.swift and fixing SPM build errors.

How To Use SwiftMessages With SPM?

If you really want to include SwiftMessages via SPM and not via Carthage/CocoaPods, there is a simple way. Swift Package Manager can be used to include and build the Swift sources; then, the resources must manually be added to your main target – this works without any problems.

This solution is natural and has a similar feel to SPM as it handles resource updating automatically. You can set it up in three steps:

  1. Add SwiftMessages to your project via Swift Package Manager (using the newest 8.0.2 release)
  2. Here is a directory containing all SwiftMessages resources. Just drop it somewhere into your project. SwiftMessages-Resources.zip
  3. Now, just adapt the destination in below build script and add it as a build phase if you want resource auto-updating (i.e. when a new release of SwiftMessages changes some of the resources, they are also automatically updated in your project – no manual work for you!)
    source="${BUILD_DIR}/../../SourcePackages/checkouts/SwiftMessages/SwiftMessages/Resources"
    destination="${PROJECT_DIR}/Path_To_SwiftMessages_Resource_Folder"
    rsync -r "${source}" "${destination}/"

    Only change Path_To_SwiftMessages_Resource_Folder, the rest should stay as is.

Thats the closest we can get to SPM until Swift 5.3 is released. Again, it does work. I think this is worth a consideration for everyone who wants to use SwiftMessages with SPM now and not wait until Swift 5.3.

fredpi commented 4 years ago

@knothed Thanks for this proposal!

While this method will also work if a resource gets updated, it won't work when entire resource files get added / removed.

But as a workaround until Swift 5.3 arrives, this is still a great way to use SwiftMessages via SPM! 🎉

wtmoose commented 4 years ago

This is in 8.0.2. Sorry for taking so long.

wtmoose commented 4 years ago

@knothed initial implementation of full SPM support is on the work/xcode12 branch

wtmoose commented 3 years ago

The script provided by @knothed fails for archive builds because the build directory structure is different. Here's an alternate script that should work universally. Just change destination as described above.

if [[ "${BUILD_DIR}" =~ (^.*DerivedData\/[^\/]*\/) ]]
then
    source="${BASH_REMATCH[1]}SourcePackages/checkouts/SwiftMessages/SwiftMessages/Resources"
else
    echo "Unexpected build directory structure ${BUILD_DIR}"
    exit 1    
fi
destination="${PROJECT_DIR}/SwiftMessagesResources"
rsync -r "${source}" "${destination}/"