Skip to content

Commit ffdf538

Browse files
committed
Try workaround for Sendable on Xcode 16.2
1 parent 88e16fb commit ffdf538

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

FirebaseAI/Sources/PartsRepresentable+Image.swift

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ enum ImageConversionError: Error {
5050
#elseif canImport(AppKit)
5151
/// Enables images to be representable as ``PartsRepresentable``.
5252
@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] {
5555
guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else {
5656
return [ErrorPart(ImageConversionError.invalidUnderlyingImage)]
5757
}
@@ -63,13 +63,22 @@ enum ImageConversionError: Error {
6363
return [InlineDataPart(data: data, mimeType: "image/jpeg")]
6464
}
6565
}
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)
6776

6877
#if !os(watchOS) // This code does not build on watchOS.
6978
/// Enables `CGImages` to be representable as model content.
7079
@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] {
7382
let output = NSMutableData()
7483
guard let imageDestination = CGImageDestinationCreateWithData(
7584
output, UTType.jpeg.identifier as CFString, 1, nil
@@ -86,13 +95,22 @@ enum ImageConversionError: Error {
8695
return [ErrorPart(ImageConversionError.couldNotConvertToJPEG)]
8796
}
8897
}
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+
89107
#endif // !os(watchOS)
90108

91109
#if canImport(CoreImage)
92110
/// Enables `CIImages` to be representable as model content.
93111
@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] {
96114
let context = CIContext()
97115
let jpegData = (colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB))
98116
.flatMap {
@@ -107,4 +125,13 @@ enum ImageConversionError: Error {
107125
return [ErrorPart(ImageConversionError.couldNotConvertToJPEG)]
108126
}
109127
}
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+
110137
#endif // canImport(CoreImage)

0 commit comments

Comments
 (0)