Skip to content

Conversation

@Kosikowski
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant