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] garden #12

Open
wants to merge 7 commits into
base: rft_1_garden
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions WeatherForecast/WeatherForecast.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,35 @@
objects = {

/* Begin PBXBuildFile section */
9995F0702B74AB48007D1105 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9995F06F2B74AB48007D1105 /* Utils.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 */; };
C7743D912B21C38100DF0D09 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7743D902B21C38100DF0D09 /* ViewController.swift */; };
C7743D912B21C38100DF0D09 /* WeatherForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7743D902B21C38100DF0D09 /* WeatherForecastViewController.swift */; };
C7743D942B21C38100DF0D09 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7743D922B21C38100DF0D09 /* Main.storyboard */; };
C7743D962B21C38200DF0D09 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7743D952B21C38200DF0D09 /* Assets.xcassets */; };
C7743D992B21C38200DF0D09 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7743D972B21C38200DF0D09 /* LaunchScreen.storyboard */; };
C7743DA12B21C3B400DF0D09 /* WeatherTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7743DA02B21C3B400DF0D09 /* WeatherTableViewCell.swift */; };
C7743DA32B21CA8600DF0D09 /* WeatherDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7743DA22B21CA8500DF0D09 /* WeatherDetailViewController.swift */; };
FFC9B6D92B6FB0DD00BBFBE1 /* TransforJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC9B6D82B6FB0DD00BBFBE1 /* TransforJSON.swift */; };
FFD4BC672B72E19D008F83F1 /* InfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD4BC662B72E19D008F83F1 /* InfoModel.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
9995F06F2B74AB48007D1105 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.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>"; };
C7743D8E2B21C38100DF0D09 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
C7743D902B21C38100DF0D09 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
C7743D902B21C38100DF0D09 /* WeatherForecastViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherForecastViewController.swift; sourceTree = "<group>"; };
C7743D932B21C38100DF0D09 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
C7743D952B21C38200DF0D09 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C7743D982B21C38200DF0D09 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C7743D9A2B21C38200DF0D09 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C7743DA02B21C3B400DF0D09 /* WeatherTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherTableViewCell.swift; sourceTree = "<group>"; };
C7743DA22B21CA8500DF0D09 /* WeatherDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherDetailViewController.swift; sourceTree = "<group>"; };
FFC9B6D82B6FB0DD00BBFBE1 /* TransforJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransforJSON.swift; sourceTree = "<group>"; };
FFD4BC662B72E19D008F83F1 /* InfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoModel.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -43,6 +49,43 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
9995F06B2B745A8C007D1105 /* App */ = {
isa = PBXGroup;
children = (
C7743D8C2B21C38100DF0D09 /* AppDelegate.swift */,
C7743D8E2B21C38100DF0D09 /* SceneDelegate.swift */,
);
path = App;
sourceTree = "<group>";
};
9995F06C2B745AAA007D1105 /* WeatherData */ = {
isa = PBXGroup;
children = (
FFD4BC662B72E19D008F83F1 /* InfoModel.swift */,
C741F66F2B58F00500A4DDC0 /* Weather.swift */,
);
path = WeatherData;
sourceTree = "<group>";
};
9995F06D2B745AF9007D1105 /* Extension */ = {
isa = PBXGroup;
children = (
FFC9B6D82B6FB0DD00BBFBE1 /* TransforJSON.swift */,
9995F06F2B74AB48007D1105 /* Utils.swift */,
);
path = "Extension ";
sourceTree = "<group>";
};
9995F06E2B745B1D007D1105 /* WeatherView */ = {
isa = PBXGroup;
children = (
C7743DA02B21C3B400DF0D09 /* WeatherTableViewCell.swift */,
C7743DA22B21CA8500DF0D09 /* WeatherDetailViewController.swift */,
C7743D902B21C38100DF0D09 /* WeatherForecastViewController.swift */,
);
path = WeatherView;
sourceTree = "<group>";
};
C7743D802B21C38100DF0D09 = {
isa = PBXGroup;
children = (
Expand All @@ -62,12 +105,10 @@
C7743D8B2B21C38100DF0D09 /* WeatherForecast */ = {
isa = PBXGroup;
children = (
C7743D8C2B21C38100DF0D09 /* AppDelegate.swift */,
C7743D8E2B21C38100DF0D09 /* SceneDelegate.swift */,
C7743DA02B21C3B400DF0D09 /* WeatherTableViewCell.swift */,
C7743D902B21C38100DF0D09 /* ViewController.swift */,
C741F66F2B58F00500A4DDC0 /* Weather.swift */,
C7743DA22B21CA8500DF0D09 /* WeatherDetailViewController.swift */,
9995F06B2B745A8C007D1105 /* App */,
9995F06E2B745B1D007D1105 /* WeatherView */,
9995F06D2B745AF9007D1105 /* Extension */,
9995F06C2B745AAA007D1105 /* WeatherData */,
C7743D922B21C38100DF0D09 /* Main.storyboard */,
C7743D952B21C38200DF0D09 /* Assets.xcassets */,
C7743D972B21C38200DF0D09 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -148,11 +189,14 @@
buildActionMask = 2147483647;
files = (
C7743DA12B21C3B400DF0D09 /* WeatherTableViewCell.swift in Sources */,
C7743D912B21C38100DF0D09 /* ViewController.swift in Sources */,
C7743D912B21C38100DF0D09 /* WeatherForecastViewController.swift in Sources */,
9995F0702B74AB48007D1105 /* Utils.swift in Sources */,
C7743D8D2B21C38100DF0D09 /* AppDelegate.swift in Sources */,
C7743DA32B21CA8600DF0D09 /* WeatherDetailViewController.swift in Sources */,
C741F6702B58F00500A4DDC0 /* Weather.swift in Sources */,
C7743D8F2B21C38100DF0D09 /* SceneDelegate.swift in Sources */,
FFC9B6D92B6FB0DD00BBFBE1 /* TransforJSON.swift in Sources */,
FFD4BC672B72E19D008F83F1 /* InfoModel.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions WeatherForecast/WeatherForecast/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Weather Forecast View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="WeatherForecast" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="WeatherForecastViewController" customModule="WeatherForecast" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
50 changes: 50 additions & 0 deletions WeatherForecast/WeatherForecast/Extension /TransforJSON.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// NetworkService.swift
// WeatherForecast
//
// Created by 김정원 on 2/4/24.
//
import UIKit
final class TransforJSON {
static let shared = TransforJSON()
private init() {}

func fetchWeatherJSON() -> WeatherJSON?{
let jsonDecoder = JSONDecoder()
jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase
guard let data = NSDataAsset(name: "weather")?.data else {
return nil
}
let info: WeatherJSON
do {
info = try jsonDecoder.decode(WeatherJSON.self, from: data)
} catch {
print(error.localizedDescription)
return nil
}
return info
}

}
final class ImageCacheManager {
static let shared = ImageCacheManager() // 싱글턴 인스턴스
private var imageCache: NSCache<NSString, UIImage> = NSCache()

func cacheImage(_ image: UIImage, forKey key: String) {
imageCache.setObject(image, forKey: key as NSString)
log("Image cached for key: \(key)")
}

func getImage(forKey key: String) -> UIImage? {
if let cachedImage = imageCache.object(forKey: key as NSString) {
log("Returning cached image for key: \(key)")
return cachedImage
}
log("No cached image : \(key)")
return nil
}

private func log(_ message: String) {
print(message)
}
}
63 changes: 63 additions & 0 deletions WeatherForecast/WeatherForecast/Extension /Utils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Utils.swift
// WeatherForecast
//
// Created by 김정원 on 2/8/24.
//

import Foundation
import UIKit

//final class Utils {
//
// static func formatDate(date: Date)
//
//}

extension DateFormatter {
static let koreanTimeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = .none
formatter.timeStyle = .short
formatter.locale = Locale(identifier: "ko_KR")
return formatter
}()
static let date: DateFormatter = {
let formatter: DateFormatter = DateFormatter()
formatter.locale = .init(identifier: "ko_KR")
formatter.dateFormat = "yyyy-MM-dd(EEEEE) a HH:mm"
return formatter
}()

}
extension Collection {
subscript (safe index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
}
}

extension UIImageView {

static func fetchImage(iconName: String) async -> UIImage? {
let iconImage = "https://openweathermap.org/img/wn/\(iconName)@2x.png"
let cacheKey = NSString(string: iconImage)

if let cachedImage = ImageCacheManager.shared.getImage(forKey: iconImage) {
return cachedImage

}
guard let url = URL(string: iconImage) else {return nil }
do {
let(data, _) = try await URLSession.shared.data(from: url)
guard let image = UIImage(data: data) else {
return nil
}
ImageCacheManager.shared.cacheImage(image, forKey: iconImage)
return image
} catch {
print("Error fetching weather icon: \(error)")
return nil
}
}

}
27 changes: 27 additions & 0 deletions WeatherForecast/WeatherForecast/WeatherData/InfoModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// InfoModel.swift
// WeatherForecast
//
// Created by 김정원 on 2/7/24.
//

import Foundation
import UIKit

struct CityDetailInfo {

var city: City

var sunrise: String {
return DateFormatter.koreanTimeFormatter.string(from: Date(timeIntervalSince1970: city.sunrise))
}

var sunset: String {
return DateFormatter.koreanTimeFormatter.string(from: Date(timeIntervalSince1970: city.sunset))
}

init(city: City) {
self.city = city
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ enum TempUnit: String {
}
}

protocol tempStrategy {
//var
}
Loading