From e065525f46ce22de726806a4414f379aca083530 Mon Sep 17 00:00:00 2001 From: Daniel Sincere Date: Tue, 14 Oct 2025 19:38:03 -0400 Subject: [PATCH] fix build for macCatalyst, and UIKit helpers for drawing SVGs --- SwiftDraw/Sources/CanvasNSView.swift | 2 +- .../SVG+UIGraphicsImageRendererContext.swift | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 SwiftDraw/Sources/SVG+UIGraphicsImageRendererContext.swift diff --git a/SwiftDraw/Sources/CanvasNSView.swift b/SwiftDraw/Sources/CanvasNSView.swift index 897ee2b..b1eec2b 100644 --- a/SwiftDraw/Sources/CanvasNSView.swift +++ b/SwiftDraw/Sources/CanvasNSView.swift @@ -29,7 +29,7 @@ // 3. This notice may not be removed or altered from any source distribution. // -#if canImport(AppKit) +#if canImport(AppKit) && !targetEnvironment(macCatalyst) import AppKit import SwiftUI diff --git a/SwiftDraw/Sources/SVG+UIGraphicsImageRendererContext.swift b/SwiftDraw/Sources/SVG+UIGraphicsImageRendererContext.swift new file mode 100644 index 0000000..bd381c6 --- /dev/null +++ b/SwiftDraw/Sources/SVG+UIGraphicsImageRendererContext.swift @@ -0,0 +1,31 @@ +// +// SVG+UIGraphicsImageRendererContext.swift +// SwiftDraw +// +// Created by Daniel on 10/14/25. +// + +#if canImport(UIKit) +public import CoreGraphics +public import UIKit + +public extension UIGraphicsImageRendererContext { + + func draw(_ svg: SVG, in rect: CGRect? = nil) { + self.cgContext.draw(svg, in: rect) + } + + func draw(_ svg: SVG, in rect: CGRect, byTiling: Bool) { + self.cgContext.draw(svg, in: rect, byTiling: byTiling) + } + + func draw( + _ svg: SVG, + in rect: CGRect, + capInsets: (top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat), + byTiling: Bool + ) { + self.cgContext.draw(svg, in: rect, capInsets: capInsets, byTiling: byTiling) + } +} +#endif