swiftxcodeswift-package

Cannot delete files from a swift package in XCode


I've created a new swift package to store all classes from an SDK I'm developing. The idea is to reuse that swift package between other projects.

I've added the package to my current XCode project, by right clicking on the Project Navigator on XCode, and clickin on Add Package Dependencies, next clickin on "Add local..." and finally selecting the empty swift package that I had previously created.

So far so good.

I've then started moving classes form the project to the packge, and when I try to delete a file from the swift pacakge I see that the Delete command is disabled.

Why is so? How should I delete files from the swift package?

Should I be doing somethin different to have it enabled?

Thanks in advance.


Solution

  • It seems like you have opened an Xcode project that has the SPM package as a dependency, and is trying to delete a file in the SPM package from the Xcode project. That is, you are selecting a file in the "Package Dependencies" section.

    the delete button is indeed disabled here

    You should instead open the SPM package itself (File -> Open, then select the Package.swift file). Then you can delete its files. The "root" of the project navigator should be a package icon:

    you can delete files here