summaryrefslogtreecommitdiff
path: root/JuickNext/Helpers
diff options
context:
space:
mode:
Diffstat (limited to 'JuickNext/Helpers')
-rw-r--r--JuickNext/Helpers/Image+Data.swift35
1 files changed, 35 insertions, 0 deletions
diff --git a/JuickNext/Helpers/Image+Data.swift b/JuickNext/Helpers/Image+Data.swift
new file mode 100644
index 0000000..dee2693
--- /dev/null
+++ b/JuickNext/Helpers/Image+Data.swift
@@ -0,0 +1,35 @@
+//
+// Image+Data.swift
+// JuickNext
+//
+// Created by Vitaly Takmazov on 15.05.2024.
+// Copyright © 2024 com.juick. All rights reserved.
+//
+
+import Foundation
+import SwiftUI
+#if canImport(UIKit)
+import UIKit
+#elseif canImport(AppKit)
+import AppKit
+#endif
+extension Image {
+ /// Initializes a SwiftUI `Image` from data.
+ init?(data: Data) {
+#if canImport(UIKit)
+ if let uiImage = UIImage(data: data) {
+ self.init(uiImage: uiImage)
+ } else {
+ return nil
+ }
+#elseif canImport(AppKit)
+ if let nsImage = NSImage(data: data) {
+ self.init(nsImage: nsImage)
+ } else {
+ return nil
+ }
+#else
+ return nil
+#endif
+ }
+}