4

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, clicking on Add Package Dependencies, clicking 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 from the project to the package and when I try to delete a file from the Swift Package I see that the Delete command is disabled.

Why is this so? How should I delete files from the Swift Package?

Should I be doing something different to have it enabled?

3
  • 2
    You need to open the package itself to delete files. I assume you opened your Xcode project (that has the SPM package as a dependency) and tried to delete files from there? Commented Jul 10, 2024 at 14:39
  • Thanks @Sweeper. That was it! It is actually quite weird cause I can do almost anything but delete files. Seems kind of counter-intuitive. Anyway, thanks! Commented Jul 10, 2024 at 14:58
  • Investigating further into that issue. It seems to me that the disabling of the Delete command seems more lik a bug than a feature. I cannot think of nay reason why we should be able to add, edit and move files but not delete them. Commented Jul 10, 2024 at 16:58

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Sweeper. That was the case. Just let me clarify, that opening the Package.info through File->Open won't work if the project that has the dependency is open (in such case it does not open the package). You need to close the project and then the package can be opened. I do not fully understand why this is needed, though. None of the other development environments I've used in my life require that, and pretending the develpers to work only on the package is not real.
0

I found that in Xcode 16.2 creating an Xcode workspace that contains both the iOS app project and the swift package does what is expected.

  1. Create a new empty Xcode Workspace.
  2. In Finder, navigate to the root of your iOS app project and drag the .xcodeproj file to the workspace.
  3. Close and reopen the Xcode workspace.
  4. In Finder, navigate to the root of your SwiftPM package folder and drag the whole folder to the Xcode workspace (make sure that both the iOS app project and the SwiftPM package are at the same level in the Project navigator. That is, one should not be nested inside the other).
  5. Close and reopen the Xcode workspace.

Now you should be able to work on both the SwiftPM package and the iOS app project at the same time as expected (deleting files is possible, you can also use Xcode previews in both without having to switch schemes).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.