diff --git a/Keyneez/Keyneez/Global/Auth/UserSession.swift b/Keyneez/Keyneez/Global/Auth/UserSession.swift index 4306575..1581154 100644 --- a/Keyneez/Keyneez/Global/Auth/UserSession.swift +++ b/Keyneez/Keyneez/Global/Auth/UserSession.swift @@ -21,6 +21,6 @@ final class UserSession { private init() { } var profile: Profile? - var accessToken: String? = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2tleSI6MjY3LCJpYXQiOjE2NzM2MTk4NjIsImV4cCI6MTY3MzYyNzA2Mn0.oHAGQsfqdn6f_1iucx1wSHsiNacRUgMxv1aqLyADue0" + var accessToken: String? = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2tleSI6Mjc1LCJpYXQiOjE2NzM2MjcyNjQsImV4cCI6MTY3MzYzNDQ2NH0.BQ1kUEycoo7tfP5kmiQcETR6CtS3wpiqxeaqZDSfO-E" } diff --git a/Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift b/Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift index ac577c9..266ee86 100644 --- a/Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift +++ b/Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift @@ -8,36 +8,52 @@ import UIKit import Kingfisher import FirebaseStorage +// +//extension UIImageView { +// func setImage(with urlString: String) { +// let cache = ImageCache.default +// guard let imageUrl = 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)") +// } +// } +// } +//} 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) - } + func setImage(url: String) { + if let imageUrl = URL(string: url) { + let resource = ImageResource(downloadURL: imageUrl) + self.kf.setImage(with: resource) { (result) in + switch result { + case .success(_): + print("success") + case .failure(_): + print("fail") } - case .failure(let error): - print("error \(error.localizedDescription)") } } } diff --git a/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift b/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift index 6ac9623..34412ab 100644 --- a/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift +++ b/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift @@ -8,10 +8,13 @@ import UIKit import Then import SnapKit +import Kingfisher +import FirebaseStorage final class HomeContentCollectionViewCell: UICollectionViewCell { static let identifier = "HomeContentCollectionViewCell" var homeContentID = -1 + var homeContentImageURL: String = "" let repository: ContentRepository = KeyneezContentRepository() // MARK: - UI Components @@ -140,6 +143,8 @@ extension HomeContentCollectionViewCell { contentTitle.text = setTitle(fullTitle: model.contentTitle) contentIntroduction.text = model.introduction likeButton.isSelected = model.liked +// contentImageView.setImage(with: model.contentImg) + contentImageView.setImage(url: model.contentImg) } private func setTitle(fullTitle: String) -> String { guard let title = fullTitle as? String else {return ""}