@@ -50,8 +50,8 @@ enum ImageConversionError: Error {
50
50
#elseif canImport(AppKit)
51
51
/// Enables images to be representable as ``PartsRepresentable``.
52
52
@available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
53
- extension NSImage : PartsRepresentable {
54
- public var partsValue : [ any Part ] {
53
+ public extension NSImage {
54
+ var partsValue : [ any Part ] {
55
55
guard let cgImage = cgImage ( forProposedRect: nil , context: nil , hints: nil ) else {
56
56
return [ ErrorPart ( ImageConversionError . invalidUnderlyingImage) ]
57
57
}
@@ -63,13 +63,22 @@ enum ImageConversionError: Error {
63
63
return [ InlineDataPart ( data: data, mimeType: " image/jpeg " ) ]
64
64
}
65
65
}
66
- #endif
66
+
67
+ #if swift(>=6.2)
68
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
69
+ extension NSImage : PartsRepresentable { }
70
+ #else // swift(>=6.2)
71
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
72
+ extension NSImage : @unchecked @retroactive Sendable , PartsRepresentable { }
73
+ #endif
74
+
75
+ #endif // canImport(UIKit)
67
76
68
77
#if !os(watchOS) // This code does not build on watchOS.
69
78
/// Enables `CGImages` to be representable as model content.
70
79
@available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , * )
71
- extension CGImage : PartsRepresentable {
72
- public var partsValue : [ any Part ] {
80
+ public extension CGImage {
81
+ var partsValue : [ any Part ] {
73
82
let output = NSMutableData ( )
74
83
guard let imageDestination = CGImageDestinationCreateWithData (
75
84
output, UTType . jpeg. identifier as CFString , 1 , nil
@@ -86,13 +95,22 @@ enum ImageConversionError: Error {
86
95
return [ ErrorPart ( ImageConversionError . couldNotConvertToJPEG) ]
87
96
}
88
97
}
98
+
99
+ #if swift(>=6.1)
100
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , * )
101
+ extension CGImage : PartsRepresentable { }
102
+ #else // swift(>=6.1)
103
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , * )
104
+ extension CGImage : @unchecked @retroactive Sendable , PartsRepresentable { }
105
+ #endif // swift(>=6.1)
106
+
89
107
#endif // !os(watchOS)
90
108
91
109
#if canImport(CoreImage)
92
110
/// Enables `CIImages` to be representable as model content.
93
111
@available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , * )
94
- extension CIImage : PartsRepresentable {
95
- public var partsValue : [ any Part ] {
112
+ public extension CIImage {
113
+ var partsValue : [ any Part ] {
96
114
let context = CIContext ( )
97
115
let jpegData = ( colorSpace ?? CGColorSpace ( name: CGColorSpace . sRGB) )
98
116
. flatMap {
@@ -107,4 +125,13 @@ enum ImageConversionError: Error {
107
125
return [ ErrorPart ( ImageConversionError . couldNotConvertToJPEG) ]
108
126
}
109
127
}
128
+
129
+ #if swift(>=6.2)
130
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , * )
131
+ extension CIImage : PartsRepresentable { }
132
+ #else // swift(>=6.2)
133
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , * )
134
+ extension CIImage : @unchecked @retroactive Sendable , PartsRepresentable { }
135
+ #endif // swift(>=6.2)
136
+
110
137
#endif // canImport(CoreImage)
0 commit comments