forked from Keyneez/Keyneez-iOS
-
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.
[Add] Keyneez#46 - UIImageView+Extension μΆκ°
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// UIImageView+Extension.swift | ||
// Keyneez | ||
// | ||
// Created by λ°μμ on 2023/01/14. | ||
// | ||
|
||
import UIKit | ||
import Kingfisher | ||
import FirebaseStorage | ||
|
||
extension UIImageView { | ||
func setImage(with UrlString: String) { | ||
let cache = ImageCache.default | ||
guard let newUrlString = UrlString.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {return} | ||
let imageUrl = "\(StorageService.shared.imageBaseUrl)\(newUrlString)" | ||
print("μΊμ±νκ² μ°Ύμλ μ°μ΄λ url \(imageUrl)") | ||
cache.retrieveImage(forKey: imageUrl) { (result) in | ||
switch result { | ||
case .success(let value): | ||
if let image = value.image { | ||
print("μΊμκ° λκ²μ κΊΌλ΄μ΄λ€.") | ||
self.image = image | ||
} else { | ||
let storage = Storage.storage() | ||
storage.reference(forURL: imageUrl).downloadURL { (url, error) in | ||
if let error = error { | ||
print("ERROR \(error.localizedDescription)") | ||
return | ||
} | ||
guard let url = url else { | ||
return | ||
} | ||
print("μ΄λ―Έμ§ μΊμκ° λμ§ μμμ λ€μ λ€μ΄λ°λλ€.", url) | ||
let resource = ImageResource(downloadURL: url, cacheKey: imageUrl) | ||
self.kf.setImage(with: resource) | ||
} | ||
} | ||
case .failure(let error): | ||
print("error \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
} |
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