Skip to content

Commit a1e3c94

Browse files
authored
Add support for Catalyst
Merge pull request #35 from pnewell/main
2 parents 4cdcb70 + 1f23012 commit a1e3c94

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

Sources/SwiftUIKit/Images/ImageRepresentable+Resized.swift

+15-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@
88

99
import Foundation
1010

11-
#if canImport(AppKit)
11+
#if canImport(UIKit)
12+
import UIKit
13+
14+
public extension UIImage {
15+
16+
/// Create a resized copy of the image.
17+
func resized(to size: CGSize) -> UIImage? {
18+
UIGraphicsBeginImageContextWithOptions(size, false, scale)
19+
draw(in: CGRect(origin: CGPoint.zero, size: size))
20+
let result = UIGraphicsGetImageFromCurrentImageContext()
21+
UIGraphicsEndImageContext()
22+
return result
23+
}
24+
}
25+
#elseif canImport(AppKit)
1226
import AppKit
1327

1428
public extension NSImage {
@@ -26,23 +40,6 @@ public extension NSImage {
2640
}
2741
#endif
2842

29-
30-
#if canImport(UIKit)
31-
import UIKit
32-
33-
public extension UIImage {
34-
35-
/// Create a resized copy of the image.
36-
func resized(to size: CGSize) -> UIImage? {
37-
UIGraphicsBeginImageContextWithOptions(size, false, scale)
38-
draw(in: CGRect(origin: CGPoint.zero, size: size))
39-
let result = UIGraphicsGetImageFromCurrentImageContext()
40-
UIGraphicsEndImageContext()
41-
return result
42-
}
43-
}
44-
#endif
45-
4643
public extension ImageRepresentable {
4744

4845
/// Create a resized copy of the image with a new height.

Sources/SwiftUIKit/Images/ImageRepresentable.swift

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@
88

99
import SwiftUI
1010

11-
#if canImport(AppKit)
12-
import class AppKit.NSImage
11+
#if canImport(UIKit)
12+
import class UIKit.UIImage
1313

1414
/**
1515
This typealias helps bridging UIKit and AppKit when working
1616
with images in a multi-platform context.
1717
*/
18-
public typealias ImageRepresentable = NSImage
19-
#endif
20-
21-
#if canImport(UIKit)
22-
import class UIKit.UIImage
18+
public typealias ImageRepresentable = UIImage
19+
#elseif canImport(AppKit)
20+
import class AppKit.NSImage
2321

2422
/**
2523
This typealias helps bridging UIKit and AppKit when working
2624
with images in a multi-platform context.
2725
*/
28-
public typealias ImageRepresentable = UIImage
26+
public typealias ImageRepresentable = NSImage
2927
#endif
3028

3129
public extension Image {

0 commit comments

Comments
 (0)