You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use a custom AttachableImageFormat type instead of directly relying on UTType. (#1203)
This PR creates a platform-agnostic type to represent image formats for
image attachments instead of relying directly on `UTType`. The
implementation still requires `UTType` on Apple platforms, but on
non-Apple platforms we can use the same type to represent those
platforms' platform-specific image format enums (e.g. on Windows, it can
box `CLSID`.) This reduces the platform-specific API surface area for
image attachments.
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
/// The content type corresponding to this image format.
65
+
///
66
+
/// The value of this property always conforms to [`UTType.image`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/image).
67
+
publicvarcontentType:UTType{
68
+
switch kind {
69
+
case.png:
70
+
return.png
71
+
case.jpeg:
72
+
return.jpeg
73
+
caselet.systemValue(contentType):
74
+
return contentType as!UTType
75
+
}
76
+
}
77
+
78
+
/// Initialize an instance of this type with the given content type and
79
+
/// encoding quality.
80
+
///
81
+
/// - Parameters:
82
+
/// - contentType: The image format to use when encoding images.
83
+
/// - encodingQuality: The encoding quality to use when encoding images. For
84
+
/// the lowest supported quality, pass `0.0`. For the highest supported
85
+
/// quality, pass `1.0`.
86
+
///
87
+
/// If the target image format does not support variable-quality encoding,
88
+
/// the value of the `encodingQuality` argument is ignored.
89
+
///
90
+
/// If `imageFormat` is not `nil` and does not conform to [`UTType.image`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/image),
@@ -60,49 +60,12 @@ public struct _AttachableImageWrapper<Image>: Sendable where Image: AttachableAs
60
60
/// instances of this type it creates hold "safe" `NSImage` instances.
61
61
nonisolated(unsafe)var image:Image
62
62
63
-
/// The encoding quality to use when encoding the represented image.
64
-
varencodingQuality:Float
63
+
/// The image format to use when encoding the represented image.
64
+
varimageFormat:AttachableImageFormat?
65
65
66
-
/// Storage for ``contentType``.
67
-
privatevar_contentType:UTType?
68
-
69
-
/// The content type to use when encoding the image.
70
-
///
71
-
/// The testing library uses this property to determine which image format to
72
-
/// encode the associated image as when it is attached to a test.
73
-
///
74
-
/// If the value of this property does not conform to [`UTType.image`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/image),
75
-
/// the result is undefined.
76
-
varcontentType:UTType{
77
-
get{
78
-
_contentType ??.image
79
-
}
80
-
set{
81
-
precondition(
82
-
newValue.conforms(to:.image),
83
-
"An image cannot be attached as an instance of type '\(newValue.identifier)'. Use a type that conforms to 'public.image' instead."
84
-
)
85
-
_contentType = newValue
86
-
}
87
-
}
88
-
89
-
/// The content type to use when encoding the image, substituting a concrete
90
-
/// type for `UTType.image`.
91
-
///
92
-
/// This property is not part of the public interface of the testing library.
0 commit comments