I'm looking to include a demo app with a Swift Package of custom controls that shows implementation demos for each of the controls. Is there a way that I can include this in the Swift Package (and also develop/test the controls directly inside the package this way)?
Here are the steps that worked for me on Xcode 13/14/15:
MyLibrary
MyLibraryDemo
somehwere, but NOT inside the package directory*Open the project's .xcodeproj
file
Go to PROJECT
> MyLibraryDemo
> Package Dependencies
and press the 'plus' symbol
Add Local
and select the directory containing your pacakgeMyLibrary
package into your example app, and edit / update your package from within you demo project.Some Notes:
If your package / demo has other dependencies, and those other dependencies get updated, you may have to clear DerivedData
before doing an update
You may also have to close & re-open Xcode, especially if you've updated dependencies, but it still says "Cannot find package MyLibrary
"
What kind of app? SwiftPM only directly supports macOS/Linux executables.
If you want an iOS/tvOS/watchOS one you will need an Xcode project that links using a relative path to find your package. This is done by creating the example app and dragging the Package's containing directory into the Xcode project. You can then link the library. If you put this example app in the repo with the package then it will be distributed along with anyone who clones the package.
One important thing I have noticed (which is almost certainly a bug in Xcode) when doing this myself is that the Package.swift
and Example.xcodeproj
cannot be in the same directory. You have to nest the Xcode project into another directory or it will have issues building/linking a lot of the time. So if you run into any issues With what I have suggested also try this bandaid.
I have created an example on GitHub here that works for Xcode 11.3.
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