From 5a601458423cfa71b5aaca304ac69d7d897c188d Mon Sep 17 00:00:00 2001 From: Mathew Gacy Date: Wed, 3 Jul 2024 07:49:03 -0700 Subject: [PATCH] Fix build error on watchOS (#26) --- .../Helpers/Extensions/Color+Utils.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/ImageFetcherTests/Helpers/Extensions/Color+Utils.swift b/Tests/ImageFetcherTests/Helpers/Extensions/Color+Utils.swift index 0df978a..944f06f 100644 --- a/Tests/ImageFetcherTests/Helpers/Extensions/Color+Utils.swift +++ b/Tests/ImageFetcherTests/Helpers/Extensions/Color+Utils.swift @@ -49,10 +49,23 @@ public typealias Color = UIColor extension Color { public func image(_ size: CGSize = CGSize(width: 1, height: 1)) -> UIImage { + #if os(iOS) || os(tvOS) UIGraphicsImageRenderer(size: size).image { rendererContext in self.setFill() rendererContext.fill(CGRect(origin: .zero, size: size)) } + #else + UIGraphicsBeginImageContextWithOptions(size, false, 0.0) + defer { UIGraphicsEndImageContext() } + + self.setFill() + UIRectFill(CGRect(origin: .zero, size: size)) + guard let image = UIGraphicsGetImageFromCurrentImageContext() else { + fatalError("Could not generate image: UIGraphicsGetImageFromCurrentImageContext returned nil.") + } + + return image + #endif } } #endif