-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
날씨 앱 [STEP 1] eunduk2 #38
base: rft_3_eunduk2
Are you sure you want to change the base?
Changes from all commits
1125d8b
4afdca0
ec2f80c
7b75c13
9875be8
2f943ec
d8620a5
4004ec4
ff7d44f
1199e75
5cc3f1c
3a9868b
fd07a9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ImageManager.swift | ||
// WeatherForecast | ||
// | ||
// Created by EUNSUNG on 4/25/24. | ||
// | ||
|
||
import UIKit | ||
|
||
struct ImageManager { | ||
private let imageChache: NSCache<NSString, UIImage> = NSCache() | ||
|
||
func downloadImage(urlString: String) async -> UIImage? { | ||
guard let url: URL = URL(string: urlString), | ||
let (data, _) = try? await URLSession.shared.data(from: url), | ||
let image: UIImage = UIImage(data: data) else { | ||
return nil | ||
} | ||
return image | ||
} | ||
|
||
func getImageChache(forKey: String) -> UIImage? { | ||
guard let image = imageChache.object(forKey: forKey as NSString) else { return nil } | ||
return image | ||
} | ||
|
||
func setImageChache(image: UIImage, forKey: String) { | ||
imageChache.setObject(image, forKey: forKey as NSString) | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,19 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. | ||
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene. | ||
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). | ||
guard let _ = (scene as? UIWindowScene) else { return } | ||
|
||
guard let scene: UIWindowScene = (scene as? UIWindowScene) else { return } | ||
|
||
let viewController: WeatherViewController = WeatherViewController(presentable: WeatherDetailViewController(), imageManager: ImageManager()) | ||
let navigationController: UINavigationController = UINavigationController(rootViewController: viewController) | ||
navigationController.navigationBar.prefersLargeTitles = true | ||
navigationController.navigationBar.tintColor = .black | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 외부에서 프로퍼티를 변경하는것은 지양하면 좋을거 같아요~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. navigationController는 UIKit에 포함되어 있는데 외부에서 변경하지 않는 방법이 있을까요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WeatherViewController에서 self.navigationController에 접근해서 viewDidLoad 시점에 변경시켜주는게 좋아보여요! |
||
|
||
let window: UIWindow = UIWindow(windowScene: scene) | ||
window.rootViewController = navigationController | ||
|
||
self.window = window | ||
window.makeKeyAndVisible() | ||
} | ||
|
||
func sceneDidDisconnect(_ scene: UIScene) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImageCachable 과 같은 프로토콜을 선언하고, 이미지 캐시만을 담당하는 객체를 만들어서 이미지 다운로드 하는 객체와 분리해보는건 어떨까요?