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 3] hoon, karen #140

Open
wants to merge 15 commits into
base: ic_9_karen
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
64 changes: 63 additions & 1 deletion Diary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@
78274D9A2A9E26DF00AD4F50 /* DiaryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78274D992A9E26DF00AD4F50 /* DiaryCell.swift */; };
78274DA12A9E3E8E00AD4F50 /* DiaryModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78274DA02A9E3E8E00AD4F50 /* DiaryModel.swift */; };
78274DA42A9F3F0A00AD4F50 /* DateFormatter+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78274DA32A9F3F0A00AD4F50 /* DateFormatter+.swift */; };
784F30C92AB2F88F009A895B /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 784F30C82AB2F88F009A895B /* Location.swift */; };
784F30CB2AB2FE87009A895B /* DecodingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 784F30CA2AB2FE87009A895B /* DecodingManager.swift */; };
784F30CE2AB30072009A895B /* DecodingError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 784F30CD2AB30072009A895B /* DecodingError.swift */; };
78D13D952AB338B000A0D28E /* WeatherInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 78D13D942AB338B000A0D28E /* WeatherInfo.plist */; };
78D13D972AB33B6A00A0D28E /* WeatherAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D13D962AB33B6A00A0D28E /* WeatherAPI.swift */; };
92FB9B8365F3B707B891705F /* Pods_Diary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBF20D2433AEB2D78258668 /* Pods_Diary.framework */; };
9C1529112AAE140900F3203E /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C1529102AAE140800F3203E /* Shareable.swift */; };
9C184BBF2AA21892003863E7 /* CellIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C184BBE2AA21892003863E7 /* CellIdentifier.swift */; };
9C243B302AB307E1009DBF80 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C243B2F2AB307E1009DBF80 /* NetworkManager.swift */; };
9C243B322AB308BC009DBF80 /* NetworkError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C243B312AB308BC009DBF80 /* NetworkError.swift */; };
9C4621EC2AB06890004ED11A /* PersistentContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4621EB2AB06890004ED11A /* PersistentContainer.swift */; };
9C4621EE2AB0739F004ED11A /* Array+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4621ED2AB0739F004ED11A /* Array+.swift */; };
9C5A1DD62AAA3F5B00162C98 /* UITextView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5A1DD52AAA3F5B00162C98 /* UITextView+.swift */; };
9C5A1DD92AAB707A00162C98 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5A1DD82AAB707A00162C98 /* CoreDataManager.swift */; };
9C5C42F22AB36D2D004FF07A /* MappingFile.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 9C5C42F12AB36D2D004FF07A /* MappingFile.xcmappingmodel */; };
9C5C42F42AB36F6B004FF07A /* CacheManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5C42F32AB36F6B004FF07A /* CacheManager.swift */; };
9C75C4CA2A9F448400C5D1CB /* DiaryDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C75C4C92A9F448400C5D1CB /* DiaryDetailViewController.swift */; };
C739AE25284DF28600741E8F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE24284DF28600741E8F /* AppDelegate.swift */; };
C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE26284DF28600741E8F /* SceneDelegate.swift */; };
Expand All @@ -33,12 +42,22 @@
78274D992A9E26DF00AD4F50 /* DiaryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryCell.swift; sourceTree = "<group>"; };
78274DA02A9E3E8E00AD4F50 /* DiaryModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryModel.swift; sourceTree = "<group>"; };
78274DA32A9F3F0A00AD4F50 /* DateFormatter+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+.swift"; sourceTree = "<group>"; };
784F30C82AB2F88F009A895B /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
784F30CA2AB2FE87009A895B /* DecodingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingManager.swift; sourceTree = "<group>"; };
784F30CD2AB30072009A895B /* DecodingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingError.swift; sourceTree = "<group>"; };
78D13D942AB338B000A0D28E /* WeatherInfo.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = WeatherInfo.plist; sourceTree = "<group>"; };
78D13D962AB33B6A00A0D28E /* WeatherAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherAPI.swift; sourceTree = "<group>"; };
9C1529102AAE140800F3203E /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
9C184BBE2AA21892003863E7 /* CellIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellIdentifier.swift; sourceTree = "<group>"; };
9C243B2F2AB307E1009DBF80 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
9C243B312AB308BC009DBF80 /* NetworkError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkError.swift; sourceTree = "<group>"; };
9C243B332AB34C0F009DBF80 /* Diary v2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Diary v2.xcdatamodel"; sourceTree = "<group>"; };
9C4621EB2AB06890004ED11A /* PersistentContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistentContainer.swift; sourceTree = "<group>"; };
9C4621ED2AB0739F004ED11A /* Array+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+.swift"; sourceTree = "<group>"; };
9C5A1DD52AAA3F5B00162C98 /* UITextView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+.swift"; sourceTree = "<group>"; };
9C5A1DD82AAB707A00162C98 /* CoreDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
9C5C42F12AB36D2D004FF07A /* MappingFile.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = MappingFile.xcmappingmodel; sourceTree = "<group>"; };
9C5C42F32AB36F6B004FF07A /* CacheManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheManager.swift; sourceTree = "<group>"; };
9C75C4C92A9F448400C5D1CB /* DiaryDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDetailViewController.swift; sourceTree = "<group>"; };
A06CFFD4E1642CCF7B5F0BAC /* Pods-Diary.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Diary.debug.xcconfig"; path = "Target Support Files/Pods-Diary/Pods-Diary.debug.xcconfig"; sourceTree = "<group>"; };
C739AE21284DF28600741E8F /* Diary.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Diary.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -108,6 +127,7 @@
children = (
C739AE30284DF28600741E8F /* Assets.xcassets */,
C739AE35284DF28600741E8F /* Info.plist */,
78D13D942AB338B000A0D28E /* WeatherInfo.plist */,
);
path = Resource;
sourceTree = "<group>";
Expand All @@ -122,6 +142,36 @@
path = Extension;
sourceTree = "<group>";
};
784F30C62AB2F7B9009A895B /* Network */ = {
isa = PBXGroup;
children = (
784F30C72AB2F7F2009A895B /* Model */,
784F30CC2AB3004E009A895B /* Error */,
784F30CA2AB2FE87009A895B /* DecodingManager.swift */,
9C243B2F2AB307E1009DBF80 /* NetworkManager.swift */,
9C5C42F32AB36F6B004FF07A /* CacheManager.swift */,
);
path = Network;
sourceTree = "<group>";
};
784F30C72AB2F7F2009A895B /* Model */ = {
isa = PBXGroup;
children = (
784F30C82AB2F88F009A895B /* Location.swift */,
78D13D962AB33B6A00A0D28E /* WeatherAPI.swift */,
);
path = Model;
sourceTree = "<group>";
};
784F30CC2AB3004E009A895B /* Error */ = {
isa = PBXGroup;
children = (
784F30CD2AB30072009A895B /* DecodingError.swift */,
9C243B312AB308BC009DBF80 /* NetworkError.swift */,
);
path = Error;
sourceTree = "<group>";
};
9C15290F2AAE13ED00F3203E /* Protocol */ = {
isa = PBXGroup;
children = (
Expand All @@ -136,6 +186,7 @@
9C5A1DD82AAB707A00162C98 /* CoreDataManager.swift */,
9C4621EB2AB06890004ED11A /* PersistentContainer.swift */,
C739AE2D284DF28600741E8F /* Diary.xcdatamodeld */,
9C5C42F12AB36D2D004FF07A /* MappingFile.xcmappingmodel */,
);
path = CoreData;
sourceTree = "<group>";
Expand All @@ -162,6 +213,7 @@
C739AE23284DF28600741E8F /* Diary */ = {
isa = PBXGroup;
children = (
784F30C62AB2F7B9009A895B /* Network */,
9C5A1DD72AAB704700162C98 /* CoreData */,
78274D9B2A9E319500AD4F50 /* Model */,
78274D9C2A9E31A200AD4F50 /* View */,
Expand Down Expand Up @@ -254,6 +306,7 @@
78274D982A9E1F7C00AD4F50 /* .swiftlint.yml in Resources */,
C739AE34284DF28600741E8F /* LaunchScreen.storyboard in Resources */,
C739AE31284DF28600741E8F /* Assets.xcassets in Resources */,
78D13D952AB338B000A0D28E /* WeatherInfo.plist in Resources */,
C739AE2C284DF28600741E8F /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -309,20 +362,28 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9C243B302AB307E1009DBF80 /* NetworkManager.swift in Sources */,
C739AE29284DF28600741E8F /* DiaryViewController.swift in Sources */,
9C1529112AAE140900F3203E /* Shareable.swift in Sources */,
78274DA12A9E3E8E00AD4F50 /* DiaryModel.swift in Sources */,
C739AE25284DF28600741E8F /* AppDelegate.swift in Sources */,
78274DA42A9F3F0A00AD4F50 /* DateFormatter+.swift in Sources */,
9C5C42F42AB36F6B004FF07A /* CacheManager.swift in Sources */,
C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */,
9C4621EC2AB06890004ED11A /* PersistentContainer.swift in Sources */,
784F30C92AB2F88F009A895B /* Location.swift in Sources */,
784F30CB2AB2FE87009A895B /* DecodingManager.swift in Sources */,
9C5A1DD62AAA3F5B00162C98 /* UITextView+.swift in Sources */,
784F30CE2AB30072009A895B /* DecodingError.swift in Sources */,
9C75C4CA2A9F448400C5D1CB /* DiaryDetailViewController.swift in Sources */,
9C184BBF2AA21892003863E7 /* CellIdentifier.swift in Sources */,
78274D9A2A9E26DF00AD4F50 /* DiaryCell.swift in Sources */,
C739AE2F284DF28600741E8F /* Diary.xcdatamodeld in Sources */,
9C5C42F22AB36D2D004FF07A /* MappingFile.xcmappingmodel in Sources */,
9C5A1DD92AAB707A00162C98 /* CoreDataManager.swift in Sources */,
78D13D972AB33B6A00A0D28E /* WeatherAPI.swift in Sources */,
9C4621EE2AB0739F004ED11A /* Array+.swift in Sources */,
9C243B322AB308BC009DBF80 /* NetworkError.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -549,9 +610,10 @@
C739AE2D284DF28600741E8F /* Diary.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
9C243B332AB34C0F009DBF80 /* Diary v2.xcdatamodel */,
C739AE2E284DF28600741E8F /* Diary.xcdatamodel */,
);
currentVersion = C739AE2E284DF28600741E8F /* Diary.xcdatamodel */;
currentVersion = 9C243B332AB34C0F009DBF80 /* Diary v2.xcdatamodel */;
path = Diary.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
37 changes: 36 additions & 1 deletion Diary/Controller/DiaryDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ final class DiaryDetailViewController: UIViewController, Shareable {

private let diary: Diary
private let isUpdated: Bool
private var latitude: Double?
private var longitude: Double?

private let contentTextView = {
let textView = UITextView()
Expand All @@ -27,16 +29,19 @@ final class DiaryDetailViewController: UIViewController, Shareable {
override func viewDidLoad() {
super.viewDidLoad()
configure()
fetchWeather()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
saveDiary()
}

init(diary: Diary, isUpdated: Bool = true) {
init(diary: Diary, isUpdated: Bool = true, latitude: Double? = nil, longitude: Double? = nil) {
self.diary = diary
self.isUpdated = isUpdated
self.latitude = latitude
self.longitude = longitude
super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -177,3 +182,33 @@ private extension DiaryDetailViewController {
])
}
}

private extension DiaryDetailViewController {
func fetchWeather() {
guard let latitude, let longitude else {
return
}

let weather = WeatherAPI.weatherData(latitude: latitude, longitude: longitude)
Copy link

@July911 July911 Sep 15, 2023

Choose a reason for hiding this comment

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

weatherData( 는 조금 어색한 것 같습니다.
무엇을 위한 API 인지가 들어가는 이름이 적합해보입니다.

Copy link
Author

Choose a reason for hiding this comment

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

5c59781

localWeather라는 네이밍으로 수정했습니다.😊


NetworkManager.shared.fetchData(API: weather) { [weak self] result in
switch result {
case .success(let data):
do {
let decodedData: Location = try DecodingManager.decodeData(from: data)

guard let currentWeather = decodedData.weather.first else {
return
}

self?.diary.main = currentWeather.main
self?.diary.icon = currentWeather.icon
} catch {
print(error)
}
case .failure(let error):
print(error.description)
}
}
}
}
33 changes: 31 additions & 2 deletions Diary/Controller/DiaryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
//

import UIKit
import CoreLocation

final class DiaryViewController: UIViewController, Shareable {
typealias Contents = String

private var tableView = UITableView()
private var diaryList = [Diary]()
private var locationManager = CLLocationManager()
private var latitude: Double?
private var longitude: Double?

override func viewDidLoad() {
super.viewDidLoad()
configureLocationManager()
configure()
}

Expand Down Expand Up @@ -79,7 +84,8 @@ extension DiaryViewController: UITableViewDataSource {
cell.configureCell(
title: diary.title,
date: formattedDate,
preview: diary.body
preview: diary.body,
icon: diary.icon
)

return cell
Expand All @@ -101,6 +107,24 @@ private extension DiaryViewController {
}
}

extension DiaryViewController: CLLocationManagerDelegate {
private func configureLocationManager() {
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let coordinate = locations.last?.coordinate else {
return
}

latitude = coordinate.latitude
longitude = coordinate.longitude
}
}

private extension DiaryViewController {
func configure() {
configureRootView()
Expand All @@ -118,7 +142,12 @@ private extension DiaryViewController {
func configureNavigation() {
let action = UIAction { [weak self] _ in
let diary = CoreDataManager.shared.create()
let diaryDetailViewController = DiaryDetailViewController(diary: diary, isUpdated: false)
let diaryDetailViewController = DiaryDetailViewController(
diary: diary,
isUpdated: false,
latitude: self?.latitude,
longitude: self?.longitude
)
self?.navigationController?.pushViewController(diaryDetailViewController, animated: true)
}

Expand Down
2 changes: 1 addition & 1 deletion Diary/CoreData/Diary.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Diary.xcdatamodel</string>
<string>Diary v2.xcdatamodel</string>
</dict>
</plist>
10 changes: 10 additions & 0 deletions Diary/CoreData/Diary.xcdatamodeld/Diary v2.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22G91" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Diary" representedClassName="Diary" syncable="YES" codeGenerationType="class">
<attribute name="body" optional="YES" attributeType="String"/>
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="icon" optional="YES" attributeType="String"/>
<attribute name="main" optional="YES" attributeType="String"/>
<attribute name="title" optional="YES" attributeType="String"/>
</entity>
</model>
Loading