forked from codesquad-members-2021/sidedish
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// ImageDownloadManager.swift | ||
// sidedish | ||
// | ||
// Created by Song on 2021/04/28. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
class ImageDownloadManager { | ||
|
||
private let cacheURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0] | ||
|
||
func download(from imageURL: String, fileName: String, completionHandler: @escaping (String) -> ()){ | ||
let request = downloadRequest(of: imageURL, fileName: "\(fileName).png") | ||
request.responseURL { response in | ||
if response.error == nil, let filePath = response.fileURL?.path { | ||
completionHandler(filePath) | ||
} | ||
} | ||
} | ||
|
||
private func downloadRequest(of imageURL: String, fileName: String) -> DownloadRequest { | ||
let destination: DownloadRequest.Destination = {_,_ in | ||
let fileURL = self.cacheURL.appendingPathComponent(fileName) | ||
return (fileURL, [.removePreviousFile, .createIntermediateDirectories]) | ||
} | ||
return AF.download(imageURL, to: destination) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters