Skip to content

feat: add delete support for XCLocalSwiftPackageReference#1044

Merged
fortmarek merged 3 commits intotuist:mainfrom
Kosikowski:feature/delete-local-swift-package-reference
Feb 24, 2026
Merged

feat: add delete support for XCLocalSwiftPackageReference#1044
fortmarek merged 3 commits intotuist:mainfrom
Kosikowski:feature/delete-local-swift-package-reference

Conversation

@Kosikowski
Copy link
Contributor

Add delete support for XCLocalSwiftPackageReference

The delete method in PBXObjects was missing support for XCLocalSwiftPackageReference, causing local package references to remain as orphaned objects in the pbxproj when switching from local back to remote packages.

This adds handling for localSwiftPackageReferences in the delete method, matching the existing pattern for remoteSwiftPackageReferences.

Short description 📝

When programmatically managing Swift package dependencies in Xcode projects, switching a local package reference back to a remote package reference leaves orphaned XCLocalSwiftPackageReference objects in the project file. This occurs because PBXObjects.delete(reference:) handles remoteSwiftPackageReferences but not localSwiftPackageReferences.

This PR adds the missing delete support for local Swift package references, ensuring clean removal of these objects when they are no longer needed.

Solution 📦

The solution follows the existing pattern established for other object types in the delete(reference:) method. Specifically, it mirrors the implementation for remoteSwiftPackageReferences:

} else if let index = localSwiftPackageReferences.index(forKey: reference) {
    return _localSwiftPackageReferences.remove(at: index).value
}

Alternative approaches considered:
none

Implementation 👩‍💻👨‍💻

  • Added localSwiftPackageReferences handling to PBXObjects.delete(reference:) method
  • Added unit tests for add/delete operations on XCLocalSwiftPackageReference:
    • test_add_addsObjectToPBXProj — verifies adding works correctly
    • test_delete_removesObjectFromPBXProj — verifies deletion works correctly
    • test_delete_removesCorrectObject_whenMultipleExist — verifies only the targeted object is removed
    • test_delete_doesNothing_whenObjectNotInProj — verifies safe behaviour for non-existent objects
  • Verified all existing tests continue to pass

Testing 🧪

All tests pass locally:

Test Suite 'XCLocalSwiftPackageReferenceTests' passed at 2026-01-29.
    Executed 8 tests, with 0 failures (0 unexpected) in 0.003 seconds

The delete method in PBXObjects was missing support for
XCLocalSwiftPackageReference, causing local package references
to remain as orphaned objects in the pbxproj when switching
from local back to remote packages.

This adds handling for localSwiftPackageReferences in the delete
method, matching the existing pattern for remoteSwiftPackageReferences.
Tests verify that:
- Adding a local package reference to PBXProj works correctly
- Deleting a local package reference removes it from PBXProj
- Deleting one of multiple local packages removes only the correct one
- Deleting an object not in the project is a no-op
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 29, 2026
@fortmarek fortmarek changed the title Add delete support for XCLocalSwiftPackageReference feat: add delete support for XCLocalSwiftPackageReference Feb 23, 2026
Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for taking so long to review this. I believe if you merge origin/main, the checks should pass. It looks like I can't edit your PR directly to do that for you.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 23, 2026
@Kosikowski
Copy link
Contributor Author

No problem at all. All done.

@fortmarek fortmarek merged commit 54b7205 into tuist:main Feb 24, 2026
6 checks passed
@dosubot
Copy link

dosubot bot commented Feb 24, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants