summaryrefslogtreecommitdiff
path: root/JuickNext/Helpers/Image+Data.swift
blob: dee2693177ed472245b42ab305a80d82dbc1cb74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
    }
}