Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Cocoa GUI application with SwiftPM

I want to split my codebase into a library which I want to upload to github and an GUI application. I hope that using recently introduced SwiftPM is a good idea.

But all examples I've been able to find show creating a console application with swift package init --type executable.

I want to know how to create a skeleton for macOS Cocoa Application with all the pregenerated stuff like assets, storyboard and so on?

It would be great to have access to such useful thing as:

swift package build
swift package test
swift package update
...

Any ideas?

Thank you!

like image 364
Andrew Avatar asked Jul 09 '17 07:07

Andrew


Video Answer


1 Answers

This is my working solution for creating cocoa apps with SPM.

  1. Create your executable version of application: swift package init --type executable
  2. Include your packages in Package.swift
  3. Update/fetch them: swift package updateor swift package fetch
  4. Create your .xcodeproj: swift package generate-xcodeproj
  5. Open your .xcodeproj with Xcode; you'll see it as a console app.
  6. Build your solution (this build will create dependencies: .frameworks, under 'Products')
  7. Click the project name to see the targets
  8. Add a new target by pressing + button below the list, and create your cocoa/gui app
  9. After adding the app, click the app name on the targets list
  10. Under General tab locate Embedded Binaries section.
  11. Press + to add binaries, and select your referenced libraries.
  12. Work on your cocoa app.
  13. When you build, .frameworks will be embedded into .app

If you update your packages.swift, you should repeat above, except creating the new target; you'll just need to add it to the project.

like image 143
ANSerpen Avatar answered Oct 19 '22 20:10

ANSerpen