I am migrating an app to Swift Package Manager. All my images are in an .xcassets
, with their configurations for different display sizes etc.
How can I migrate those assets to SPM?
To add a new Swift package dependency: Select your project in the Project navigator, then select your app target and navigate to its General pane. Click the + button in the "Frameworks, Libraries, and Embedded Content" section, select the local package's library product, and add it as a dependency.
To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.
I am migrating an app to Swift Package Manager. All my images are in an .xcassets, with their configurations for different display sizes etc. How can I migrate those assets to SPM? Show activity on this post. Starting with XCode 12 and Swift 5.3, it is possible to include images in Swift Package. I had to do a few modifications:
The idea of Swift Package Manager is that you should simply be able to go to: The native Swift Package Manager is built into Xcode and eliminates the need to install the package dependency manager using Homebrew, like you would for Carthage, or even having to run a simple “sudo gem install” command like you would for CocoaPods.
A Swift package can contain multiple products (a product is a framework or an executable), you can select and integrate them individually in Xcode. Finally Xcode will do the required integration process, like embedding the library into the project and some other build configuration changes… Now you are ready to import your framework in your target.
Migration types are ‘copy’ and ‘move’. Select the’ move’ radio button if you wish to delete the source catalog after the migration is done. The default type is ‘copy’. Catalog folders, projects, and environments have explicit permissions.
Starting with XCode 12 and Swift 5.3, it is possible to include images in Swift Package. I had to do a few modifications:
// swift-tools-version:5.3
as the header of the Swift package file.assets
folder get compiled automatically.
public func SCImage(named name: String) -> UIImage? {
UIImage(named: name, in: Bundle.module, compatibleWith: nil)
}
I can now do
import SCImages
let image = SCImage(named: "foo")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With