Use R.swift for resources in your own Swift package.
-
This is a plugin for Swift Package Manager, which supports plugins since Swift 5.6, therefore the proper swift tools needs to be used
// swift-tools-version:5.6
-
You need two dependencies,
R.swift.Library
as usual, but alsoR.swift.Plugin
dependencies: [ .package(url: "https://github.com/mac-cain13/R.swift.Library", from: "5.4.0"), .package(url: "https://github.com/quentinfasquel/R.swift.Plugin", from: "5.4.0") ],
-
Your target needs to link with
R.swift.Library
and use the plugintargets: [ .target( name: "YourTarget", dependencies: [.product(name: "RswiftDynamic", package: "R.swift.Library")], resources: [ .copy("someImage.png") // Resource example ], plugins: [.plugin(name: "RswiftPlugin", package: "R.swift.Plugin")] ),
-
Use R.swift like before :
let image = R.image.someImage()
--
This plugin may not be bullet-proof since it was barely tested. It is awaiting to become officially supported by the official R.swift, here is what to know about how it works :
-
The SPM plugin uses an executable variant of the official R.swift. It is currently hosted through a github release built from this branch.
-
It uses
--accessLevel public
so that the resources of a package, and mostlyR.validate()
, are accessible in the package's test target. -
The executable is slightly big (~ 24Mb) since it carries along a dependency on Swift Package Manager's own package model
-
Your feedback is welcome!