Skip to content
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

Open
wants to merge 13 commits into
base: rft_3_eunduk2
Choose a base branch
from
16 changes: 16 additions & 0 deletions WeatherForecast/WeatherForecast.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
61C1CA882BCD585500932E4A /* WeatherViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61C1CA872BCD585500932E4A /* WeatherViewController.swift */; };
61C1CA8A2BCD586900932E4A /* WeatherView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61C1CA892BCD586900932E4A /* WeatherView.swift */; };
61E8B7922BD41BD600802B65 /* WeatherDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E8B7912BD41BD600802B65 /* WeatherDetailView.swift */; };
61E8B7942BDA864B00802B65 /* ImageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E8B7932BDA864B00802B65 /* ImageManager.swift */; };
C741F6702B58F00500A4DDC0 /* Weather.swift in Sources */ = {isa = PBXBuildFile; fileRef = C741F66F2B58F00500A4DDC0 /* Weather.swift */; };
C7743D8D2B21C38100DF0D09 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7743D8C2B21C38100DF0D09 /* AppDelegate.swift */; };
C7743D8F2B21C38100DF0D09 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7743D8E2B21C38100DF0D09 /* SceneDelegate.swift */; };
Expand All @@ -19,6 +23,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
61C1CA872BCD585500932E4A /* WeatherViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherViewController.swift; sourceTree = "<group>"; };
61C1CA892BCD586900932E4A /* WeatherView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherView.swift; sourceTree = "<group>"; };
61E8B7912BD41BD600802B65 /* WeatherDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherDetailView.swift; sourceTree = "<group>"; };
61E8B7932BDA864B00802B65 /* ImageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageManager.swift; sourceTree = "<group>"; };
C741F66F2B58F00500A4DDC0 /* Weather.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weather.swift; sourceTree = "<group>"; };
C7743D892B21C38100DF0D09 /* WeatherForecast.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WeatherForecast.app; sourceTree = BUILT_PRODUCTS_DIR; };
C7743D8C2B21C38100DF0D09 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -66,8 +74,12 @@
C7743D8E2B21C38100DF0D09 /* SceneDelegate.swift */,
C7743DA02B21C3B400DF0D09 /* WeatherTableViewCell.swift */,
C7743D902B21C38100DF0D09 /* ViewController.swift */,
61C1CA892BCD586900932E4A /* WeatherView.swift */,
61C1CA872BCD585500932E4A /* WeatherViewController.swift */,
C741F66F2B58F00500A4DDC0 /* Weather.swift */,
61E8B7912BD41BD600802B65 /* WeatherDetailView.swift */,
C7743DA22B21CA8500DF0D09 /* WeatherDetailViewController.swift */,
61E8B7932BDA864B00802B65 /* ImageManager.swift */,
C7743D922B21C38100DF0D09 /* Main.storyboard */,
C7743D952B21C38200DF0D09 /* Assets.xcassets */,
C7743D972B21C38200DF0D09 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -148,11 +160,15 @@
buildActionMask = 2147483647;
files = (
C7743DA12B21C3B400DF0D09 /* WeatherTableViewCell.swift in Sources */,
61E8B7942BDA864B00802B65 /* ImageManager.swift in Sources */,
C7743D912B21C38100DF0D09 /* ViewController.swift in Sources */,
C7743D8D2B21C38100DF0D09 /* AppDelegate.swift in Sources */,
C7743DA32B21CA8600DF0D09 /* WeatherDetailViewController.swift in Sources */,
61C1CA882BCD585500932E4A /* WeatherViewController.swift in Sources */,
C741F6702B58F00500A4DDC0 /* Weather.swift in Sources */,
61E8B7922BD41BD600802B65 /* WeatherDetailView.swift in Sources */,
C7743D8F2B21C38100DF0D09 /* SceneDelegate.swift in Sources */,
61C1CA8A2BCD586900932E4A /* WeatherView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 7 additions & 6 deletions WeatherForecast/WeatherForecast/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wYg-u6-9nF">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Weather View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="WeatherForecast" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<viewController id="BYZ-38-t0r" customClass="WeatherViewController" customModule="WeatherForecast" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC" customClass="WeatherView" customModule="WeatherForecast" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<navigationItem key="navigationItem" id="ek7-m5-Cef"/>
<navigationItem key="navigationItem" id="PH8-jO-AEx"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
Expand Down
30 changes: 30 additions & 0 deletions WeatherForecast/WeatherForecast/ImageManager.swift
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)
}
}
Comment on lines +10 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImageCachable 과 같은 프로토콜을 선언하고, 이미지 캐시만을 담당하는 객체를 만들어서 이미지 다운로드 하는 객체와 분리해보는건 어떨까요?

14 changes: 13 additions & 1 deletion WeatherForecast/WeatherForecast/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

외부에서 프로퍼티를 변경하는것은 지양하면 좋을거 같아요~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navigationController는 UIKit에 포함되어 있는데 외부에서 변경하지 않는 방법이 있을까요??

Copy link

Choose a reason for hiding this comment

The 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) {
Expand Down
Loading