summaryrefslogtreecommitdiff
path: root/JuickNext/Helpers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-05-15 09:38:05 +0300
committerGravatar Vitaly Takmazov2024-05-15 09:38:05 +0300
commitf2bf132d6df251ea7d5224d0d86c2ca5b0c02320 (patch)
tree0e3206404d934c8bff590ba1f3c757ab05192def /JuickNext/Helpers
parent1b058af687bac9dfe8c78209fe7ba510b2d78257 (diff)
Integrate feeds from good old `tst` 2019 project
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
+ }
+}