Add delete support for XCLocalSwiftPackageReference #1044
+72
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add delete support for XCLocalSwiftPackageReference
The
deletemethod inPBXObjectswas missing support forXCLocalSwiftPackageReference, causing local package references to remain as orphaned objects in the pbxproj when switching from local back to remote packages.This adds handling for
localSwiftPackageReferencesin the delete method, matching the existing pattern forremoteSwiftPackageReferences.Short description 📝
When programmatically managing Swift package dependencies in Xcode projects, switching a local package reference back to a remote package reference leaves orphaned
XCLocalSwiftPackageReferenceobjects in the project file. This occurs becausePBXObjects.delete(reference:)handlesremoteSwiftPackageReferencesbut notlocalSwiftPackageReferences.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 forremoteSwiftPackageReferences:Alternative approaches considered:
none
Implementation 👩💻👨💻
localSwiftPackageReferenceshandling toPBXObjects.delete(reference:)methodXCLocalSwiftPackageReference:test_add_addsObjectToPBXProj— verifies adding works correctlytest_delete_removesObjectFromPBXProj— verifies deletion works correctlytest_delete_removesCorrectObject_whenMultipleExist— verifies only the targeted object is removedtest_delete_doesNothing_whenObjectNotInProj— verifies safe behaviour for non-existent objectsTesting 🧪
All tests pass locally: