Prefer native Swift Testing image attachments on supported toolchains#1067
Merged
stephencelis merged 3 commits intopointfreeco:mainfrom Mar 19, 2026
Merged
Conversation
On Swift 6.3+ (Xcode 26.4+), CGImage/UIImage/NSImage/CIImage conform to Attachable. Add a helper that detects .png attachment names and records native image attachments instead of raw Data, enabling better Xcode integration (preview, thumbnails). Falls back to data attachments on older toolchains or for non-image data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This builds on the Swift Testing attachment support added in #1064 and refined in #1065.
Currently, Swift Testing attachments in
AssertSnapshot.swiftare recorded as genericDataattachments viaAttachment.record(data, ...). On newer toolchains, Swift Testing supports attaching image types directly, so PNG snapshot artifacts can be recorded as native image attachments instead.This change adds a small helper to prefer native Swift Testing image attachments for PNG snapshot artifacts when supported, while preserving the existing fallback behavior everywhere else.
What changes
recordSwiftTestingAttachmenthelper.pngattachments on supported toolchains:UIImage/NSImageAttachment.record(..., as: .png, sourceLocation: ...)Attachment.record(data, ...)pathSourceLocationbehavior from Record attachment when recording new snapshots. #1065Notes
Dataattachment behavior.Xcode 26.4 adds native Swift Testing image attachments, so this change aligns SnapshotTesting’s PNG snapshot artifacts with the newer test-reporting API on supported toolchains.