Skip to content

Commit

Permalink
[Add] Keyneez#46 - UIImageView+Extension μΆ”κ°€
Browse files Browse the repository at this point in the history
  • Loading branch information
kpk0616 committed Jan 13, 2023
1 parent e5f81d2 commit 0c338e7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Keyneez/Keyneez.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -284,6 +285,7 @@
B1A8037F296EA54E0007DDD9 /* UserAPIProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserAPIProvider.swift; sourceTree = "<group>"; };
B1A80381296EA66F0007DDD9 /* GenericResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericResponse.swift; sourceTree = "<group>"; };
B1B21D16295DE0660083D9EE /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
B81EE0042971B6FA00167750 /* UIImageView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Extension.swift"; sourceTree = "<group>"; };
B8C02F012962F4AF005612CE /* KeyneezTabbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyneezTabbar.swift; sourceTree = "<group>"; };
B8C02F042962F5D4005612CE /* SettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewController.swift; sourceTree = "<group>"; };
B8C02F082962F646005612CE /* MyPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MyPageViewController.swift; path = Keyneez/Tab/MyPage/MyPageViewController.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -756,6 +758,7 @@
B8C02F2F296B185B005612CE /* UISegmentedControl+Extension.swift */,
B8C02F41296C3983005612CE /* UIViewController+Extension.swift */,
B8FC663F297057A400AEE9C3 /* UILabel+Extension.swift */,
B81EE0042971B6FA00167750 /* UIImageView+Extension.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
44 changes: 44 additions & 0 deletions Keyneez/Keyneez/Global/Views/UIImageView+Extension.swift
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)")
}
}
}
}
27 changes: 26 additions & 1 deletion Keyneez/Keyneez/Tab/KeyneezTabbarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ final class KeyneezTabbarController: UITabBarController {
assignTabbar()
createTabbarItems()
}

// let repository = KeyneezContentRepository()

private func assignTabbar() {
let tabBar = { () -> KeyneezTabar in
Expand All @@ -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"),
Expand All @@ -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
}

Expand All @@ -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
// }
}

0 comments on commit 0c338e7

Please sign in to comment.