8

My Swift library FlexColorPicker just adopted Swift Package Manager support. The library itself can be added to any project via XCode by doing File → Swift Packages → Add Package Dependency... → choose target → enter https://github.com/RastislavMirek/FlexColorPicker → confirm. However, there is a demo that comes with the library that cannot be run when installed this way.

I want to add another (probably executable) product FlexColorPickerDemo to Package.swift that users can chose to include (or exclude) and then run inside their project just to see what they can do with the library. Besides adding new product and target to the Package.swift file I probably need to add main.swift, right? How should it look so that it allows running the demo as iOS app when installed via SPM?

Any help appreciated, even tutorial link, I don't really know what to Google...

Rasto
  • 17,204
  • 47
  • 154
  • 245
  • That is now possible, I described the folder hierarchy and command lines in that answer: https://stackoverflow.com/questions/64758546/can-i-specify-a-platform-target-when-running-swift-test-from-the-cli/65256621#65256621 – itMaxence Dec 11 '20 at 18:57

1 Answers1

1

You want a complete demo project to be 'included' in a Package.swift file?

That's not possible, the same reason why bundled resources aren't useable (yet) by SwiftPM: How to include assets / resources in a Swift Package Manager library?

Best way imho would be to update your README file and explain how users can test the library, just like you're already doing.

basvk
  • 4,437
  • 3
  • 29
  • 49
  • 1
    I do not see how the 2 questions are related... My demo project has no bundled resources/assests. So what is the reason why it should be impossible specifically? – Rasto Oct 10 '19 at 15:36
  • 1
    Because Package.swift only allows the inclusion of swift or obj-c files. So everything else (resources, xcodeproj, plist) can not. So therefor those 2 questions are related. While the possibility for SwiftPM to eventually handle bundles is more likely then the ability to create a demo project (similar to `pod try`) SwiftPM is created for handling dependencies, not entire projects. – basvk Oct 11 '19 at 07:43
  • I see. But do I really need xcodeproj and plist to run a demo? Perhaps it can be replaced by starting the loop from `main.swift` with the storyboard as starting point. But not sure it can run in simulator this way... – Rasto Oct 11 '19 at 11:59
  • Can't you just create a Demo directory inside repository with the example project inside? And maybe use your Swift package as a local dependency? I don't see any downsides of that idea. – Mateusz Nov 06 '19 at 21:54
  • Now that we can include resources, is it possible to build an example app in a Swift Package Manager package? – Austin Sep 05 '20 at 22:43
  • Have a look here: https://stackoverflow.com/a/67580251/13292535 – Sardorbek Ruzmatov May 18 '21 at 05:07