How do I use Swift Package Manager with an existing macOS project?

后端 未结 4 1806
北海茫月
北海茫月 2021-01-03 20:30

I\'ve been using Cocoapods to manage dependencies for my Swift project. I came across this package which is not listed at Cocoapods. Instead it suggests using Swift Package

相关标签:
4条回答
  • 2021-01-03 20:41

    Update for XCode 11

    This is A LOT easier now with XCode 11. As of this writing the current version of XCode is 11.3.1.

    For an existing XCode project simply:

    1. go to File->Swift Packages->Add Package Dependency...
    2. enter the URL of the hosted package you want to add
    3. choose the rules about which versions your app will use
    4. click Finish

    0 讨论(0)
  • 2021-01-03 20:43

    I think SPM is only compatible with Mac command line executables or libraries. This explicitly states SPM doesn't support iOS, watchOS, or tvOS platforms at all. But, since macOS AppKit/Cocoa application targets are very similar to iOS or tvOS Xcode targets, I would say this statement implies that SPM can't be used with macOS Cocoa applications out of the box either, which is what I think you're hoping for.

    It looks like there is some work here on how to use it with iOS application targets which should largely translate to a macOS Cocoa target.

    0 讨论(0)
  • 2021-01-03 20:47

    You can create a windowed application using SPM (I have a whole project sitting waiting for ABI that does this) you just need some boiler plate in swift.main. I’ll dig it out.

    However the method others are suggesting is never going to work (with current versions of SPM).

    However, what I am seeing is that you really want to use SPM to manage dependencies (keeping up to date etc). So I think you could do that much more easily.

    Rather than creating a executable as your default target, instead create a library (perhaps call it basic-ssh-dependencies). Generate your Xcode project and drag THAT into your primary Xcode project and configure your target to to depend on it. When you update the library from SPM for changes in dependencies you should re-gen your Xcode-proj.

    Let me know your mileage and any wrinkles, or if I’ve misunderstood what you are trying to achieve.

    0 讨论(0)
  • 2021-01-03 20:50

    Until the time of this writing answer, Swift Package Manager do not support the iOS, tvOS, and watchOS. Instead, you will have to add the files from the package directly to your project.

    I would suggest you creating a Dependencies group in your project and a group below that with the package name, like this answer:

    So, first you will add the files dependency that you want to import into your project to the name of the package name that included in Dependencies group that we make before.

    After you add the files then you can access the code as you usually would when you write it yourself like the image below. No need imports. You can see more details in here. hope it helps.

    0 讨论(0)
提交回复
热议问题