From 0c338e75802fc928787346d48061ce90e827d9fa Mon Sep 17 00:00:00 2001 From: kpk0616 Date: Sat, 14 Jan 2023 00:58:17 +0900 Subject: [PATCH] =?UTF-8?q?[Add]=20#46=20-=20UIImageView+Extension=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Keyneez/Keyneez.xcodeproj/project.pbxproj | 4 ++ .../Global/Views/UIImageView+Extension.swift | 44 +++++++++++++++++++ .../Keyneez/Tab/KeyneezTabbarController.swift | 27 +++++++++++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift diff --git a/Keyneez/Keyneez.xcodeproj/project.pbxproj b/Keyneez/Keyneez.xcodeproj/project.pbxproj index d597f4b..3d7fa75 100644 --- a/Keyneez/Keyneez.xcodeproj/project.pbxproj +++ b/Keyneez/Keyneez.xcodeproj/project.pbxproj @@ -116,6 +116,7 @@ B1A80380296EA54E0007DDD9 /* UserAPIProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1A8037F296EA54E0007DDD9 /* UserAPIProvider.swift */; }; B1A80382296EA66F0007DDD9 /* GenericResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1A80381296EA66F0007DDD9 /* GenericResponse.swift */; }; B1B21D17295DE0660083D9EE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = B1B21D16295DE0660083D9EE /* .swiftlint.yml */; }; + B81EE0052971B6FA00167750 /* UIImageView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B81EE0042971B6FA00167750 /* UIImageView+Extension.swift */; }; B8C02F022962F4AF005612CE /* KeyneezTabbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C02F012962F4AF005612CE /* KeyneezTabbar.swift */; }; B8C02F052962F5D4005612CE /* SettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C02F042962F5D4005612CE /* SettingViewController.swift */; }; B8C02F092962F646005612CE /* MyPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C02F082962F646005612CE /* MyPageViewController.swift */; }; @@ -284,6 +285,7 @@ B1A8037F296EA54E0007DDD9 /* UserAPIProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserAPIProvider.swift; sourceTree = ""; }; B1A80381296EA66F0007DDD9 /* GenericResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericResponse.swift; sourceTree = ""; }; B1B21D16295DE0660083D9EE /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = ""; }; + B81EE0042971B6FA00167750 /* UIImageView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Extension.swift"; sourceTree = ""; }; B8C02F012962F4AF005612CE /* KeyneezTabbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyneezTabbar.swift; sourceTree = ""; }; B8C02F042962F5D4005612CE /* SettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewController.swift; sourceTree = ""; }; B8C02F082962F646005612CE /* MyPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MyPageViewController.swift; path = Keyneez/Tab/MyPage/MyPageViewController.swift; sourceTree = SOURCE_ROOT; }; @@ -756,6 +758,7 @@ B8C02F2F296B185B005612CE /* UISegmentedControl+Extension.swift */, B8C02F41296C3983005612CE /* UIViewController+Extension.swift */, B8FC663F297057A400AEE9C3 /* UILabel+Extension.swift */, + B81EE0042971B6FA00167750 /* UIImageView+Extension.swift */, ); path = Views; sourceTree = ""; @@ -1357,6 +1360,7 @@ 0233C6FA296C8D0D00A177E9 /* SimplePwdViewController.swift in Sources */, 0253816729674D3D00D29A97 /* LandingPageViewController.swift in Sources */, B10AAD43296967D000AB8475 /* CustomNavigationAnimator.swift in Sources */, + B81EE0052971B6FA00167750 /* UIImageView+Extension.swift in Sources */, B8C02F38296B3F6E005612CE /* HomeSearchCollectionViewCell.swift in Sources */, B18B60D7296552DA00AF14F5 /* NavigationViewBuilder.swift in Sources */, B1A8037E296E9DF20007DDD9 /* UserAPI.swift in Sources */, diff --git a/Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift b/Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift new file mode 100644 index 0000000..ac577c9 --- /dev/null +++ b/Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift @@ -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)") + } + } + } +} diff --git a/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift b/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift index a927aed..7c9997c 100644 --- a/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift +++ b/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift @@ -20,6 +20,8 @@ final class KeyneezTabbarController: UITabBarController { assignTabbar() createTabbarItems() } + +// let repository = KeyneezContentRepository() private func assignTabbar() { let tabBar = { () -> KeyneezTabar in @@ -37,6 +39,21 @@ final class KeyneezTabbarController: UITabBarController { // MARK: - Setting ViewController in TabbarViewController extension KeyneezTabbarController { fileprivate func createTabbarItems() { + +// let homeViewController = HomeViewController() +// let homeViewNavigationController = makeHomeNaviController(homeViewController: homeViewController) +// +// guard let token = UserSession.shared.accessToken else { return } +// repository.getAllContents(token: token) { +// [weak self] arr in +// homeViewController.datasources.append(arr) +// DispatchQueue.main.async { +// homeViewController.VCs.forEach { +// $0.contentList = homeViewController.datasources[0] +// } +// } +// } + let tabInfos: [TabInfo] = [ TabInfo(viewController: HomeViewController.self, title: "홈", imageName: "ic_home_tabbar"), TabInfo(viewController: LikeViewController.self, title: "좋아요", imageName: "ic_like_tabbar"), @@ -46,9 +63,10 @@ extension KeyneezTabbarController { TabInfo(viewController: SettingViewController.self, title: "설정", imageName: "ic_more_tabbar") ] - let navigations = tabInfos.map { + var navigations = tabInfos.map { makeViewController(viewController: $0.viewController!, title: $0.title, imageName: $0.imageName) } +// navigations.insert(homeViewNavigationController, at: 0) self.viewControllers = navigations } @@ -64,4 +82,11 @@ extension KeyneezTabbarController { UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage: nil) return nav } + +// private func makeHomeNaviController(homeViewController: HomeViewController) -> UINavigationController { +// let nav = UINavigationController(rootViewController: homeViewController) +// nav.isNavigationBarHidden = true +// nav.tabBarItem = UITabBarItem(title: "홈", image: UIImage(named: "ic_home_tabbar"), selectedImage: nil) +// return nav +// } }