-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIImage+Data.swift
More file actions
35 lines (28 loc) · 899 Bytes
/
UIImage+Data.swift
File metadata and controls
35 lines (28 loc) · 899 Bytes
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
//
// UIImage+Data.swift
//
// Created by Pushpank on 13/10/19.
// Copyright © 2018 Pushpank. All rights reserved.
//
import Foundation
class ImageData {
static func imageUrlToData(urlString: String) -> Data {
guard let url = URL(string: urlString) else {return Data()}
var imageData = Data()
if let data = try? Data(contentsOf: url) {
imageData = data
}
return imageData
}
static func createLocalURL(urlString: String) -> URL? {
let data = ImageData.imageUrlToData(urlString: urlString)
let localUrl = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("copy.png")
do {
try data.write(to: localUrl)
} catch let error {
print("Failed to write to URL")
print(error)
}
return localUrl
}
}