skip to Main Content

Is there a way I can use package.swift in an Xcode project? I have written a package.swift file which is being read/ understood by swift build, but it looks like Xcode still doesn’t know about this file. I don’t want to use the built-in Swift Packages tab because I don’t know how Xcode handles that (e.g. where do the contents get version controlled?).

I have a feeling I’m asking something impossible, as using a project package.swift may be mutually exclusive to XCode.

I did read Use swift package manager on existing xcode project but the answer here recommended using the Xcode swift package manager feature, which is what I am trying not to use.

2

Answers


  1. Chosen as BEST ANSWER

    I don't think this is possible. If you use a Swift package (and therefore you have a package.swift, you won't get the rich menus provided by Xcode.

    I'm hoping interoperability will come in the future, like how Android Studio and Gradle config files (build.gradle) work together. Swift packages and Xcode projects do not work together at all.


  2. To use a Swift package as an Xcode project, just open the Package.swift directly. Xcode will create a workspace (in comments, I said a project, but it’s a workspace) in the package’s .swiftpm directory. There won’t be any project settings, because you do that by editing the Package.swift file, and files are always sorted. Other than that, it’s pretty much like working in an Xcode project, including debugging and testing.

    Of course there are the other modes of using a package

    You can just drag the Package.swift file into your Xcode project, if it’s a local package. You’ll also need to add it as a dependency in your General settings, just as you would any framework. That’s not the same as the "Add Package Dependency" feature. It’s the same Project Settings -> Target -> Frameworks & Libraries that you use for any traditional framework.

    If you do it that way, the package is part of the Xcode project.

    If the package is already under it’s own git repo, Xcode will prompt you which repo you want to do things like "push" or whatever, though commit just applies to whatever repo the files being committed belong to… so if you change some app code and package code, and commit them both at the same time, the app code would go into the app’s repo, and the package code would go to the package’s repo.

    If the package isn’t under source control and you relocate it to your project folder, I think the project’s repo will take responsibility for those sources, though you might have to explicitly check them in Xcode’s commit (or git add from the command line).

    I’m not sure how it handles it, if it’s in an unrelated folder and not in its own repo.

    If it’s a remote package, which is different, you need to add it as a package dependency. No getting around that for remote packages.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search