summaryrefslogtreecommitdiff
path: root/Juick/ImageFetcher.swift
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-09-17 00:46:27 +0300
committerGravatar Vitaly Takmazov2020-12-10 18:59:55 +0300
commitcf97b1cd43a91725e0419a953815287fde0bf70f (patch)
tree82961197cf7fa1bfa40550748ddd309e5e4d38c3 /Juick/ImageFetcher.swift
parent4851a21c41488a6f0c01e60f1bd1472846f816bf (diff)
SwiftUI WIP
Diffstat (limited to 'Juick/ImageFetcher.swift')
-rw-r--r--Juick/ImageFetcher.swift28
1 files changed, 28 insertions, 0 deletions
diff --git a/Juick/ImageFetcher.swift b/Juick/ImageFetcher.swift
new file mode 100644
index 0000000..f76c0ba
--- /dev/null
+++ b/Juick/ImageFetcher.swift
@@ -0,0 +1,28 @@
+//
+// ImageFetcher.swift
+// tst
+//
+// Created by Vitaly Takmazov on 10.12.2019.
+// Copyright © 2019 com.juick. All rights reserved.
+//
+
+import Foundation
+import Combine
+
+class ImageFetcher: ObservableObject {
+
+ @Published var data: Data = Data()
+
+ init(url: String) {
+ guard let imageUrl = URL(string: url) else {
+ return
+ }
+
+ URLSession.shared.dataTask(with: imageUrl) { (data, _, _) in
+ guard let data = data else { return }
+ DispatchQueue.main.async { [weak self] in
+ self?.data = data
+ }
+ }.resume()
+ }
+}