From 4300d01ddfe498306c99f73c337d71eddeedb2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8A=E3=82=93?= <31785428+rin-senpai@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:50:37 +1000 Subject: [PATCH] Fixed CGImages build error with watchOS --- Sources/GoogleAI/PartsRepresentable+Image.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/GoogleAI/PartsRepresentable+Image.swift b/Sources/GoogleAI/PartsRepresentable+Image.swift index 1d7a377..9dd8f76 100644 --- a/Sources/GoogleAI/PartsRepresentable+Image.swift +++ b/Sources/GoogleAI/PartsRepresentable+Image.swift @@ -19,6 +19,11 @@ import UniformTypeIdentifiers import AppKit // For NSImage extensions. #endif +#if os(watchOS) + import ImageIO + import CoreGraphics +#endif + private let imageCompressionQuality: CGFloat = 0.8 /// An enum describing failures that can occur when converting image types to model content data. @@ -38,7 +43,7 @@ public enum ImageConversionError: Error { #if canImport(UIKit) /// Enables images to be representable as ``ThrowingPartsRepresentable``. - @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *) + @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 8.0, *) extension UIImage: ThrowingPartsRepresentable { public func tryPartsValue() throws -> [ModelContent.Part] { guard let data = jpegData(compressionQuality: imageCompressionQuality) else { @@ -50,7 +55,7 @@ public enum ImageConversionError: Error { #elseif canImport(AppKit) /// Enables images to be representable as ``ThrowingPartsRepresentable``. - @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *) + @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 8.0, *) extension NSImage: ThrowingPartsRepresentable { public func tryPartsValue() throws -> [ModelContent.Part] { guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else { @@ -67,7 +72,7 @@ public enum ImageConversionError: Error { #endif /// Enables `CGImages` to be representable as model content. -@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *) +@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 9.0, *) extension CGImage: ThrowingPartsRepresentable { public func tryPartsValue() throws -> [ModelContent.Part] { let output = NSMutableData()