Hello, I am a Swift beginner trying to build a simple command line tool.
I used swift package manager to initialize my tool, and built a Xcode project file then wrote code using Xcode. I want to access some configure files in run-time, so I figured out to add a Copy Files Phase in Build Phase of Xcode project setting. It works if I build my tool in Xcode, but not using swift build.
I am wondering what I should do to add a Copy Files Phase for swift build as well? Or are their any other approach I can access files in run-time?
Since the Xcode project is generated from the SPM package, modifications done in Xcode won't affect the package itself.
SPM does not currently support resources, so you can't currently include the files you need in the package directly. You could maybe move the file contents into string literals in a Swift file. If that is not an option you'll need to handle the files yourself and make sure they are shipped with the built utility.
The big advantage of the SPM package is that it can be built on macOS, Linux and any other platforms supported by SPM. It also allows other SPM packages to depend on your code easily.
Since you're building a command line utility, you probably don't care about using your code as a dependency, so the question is: Do you want to build anywhere other than macOS?
I have had a lot of problems with Xcode and SPM, have now given up and just use Xcode (suggest you do the same). Hopefully the two will be integrated shortly :)
I just found SPM has a very neat command argument parser utility, is it possible to include SPM as a framework and use that utility in a pure Xcode command line tool project?