From f2bf132d6df251ea7d5224d0d86c2ca5b0c02320 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 15 May 2024 09:38:05 +0300 Subject: Integrate feeds from good old `tst` 2019 project --- JuickNext/Helpers/Image+Data.swift | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 JuickNext/Helpers/Image+Data.swift (limited to 'JuickNext/Helpers') 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 + } +} -- cgit v1.2.3