diff --git a/Diary.xcodeproj/project.pbxproj b/Diary.xcodeproj/project.pbxproj index d6bd7f41e..7c50a4682 100644 --- a/Diary.xcodeproj/project.pbxproj +++ b/Diary.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 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 */; }; + 782FB0992AB4B6C500BC8C12 /* Toastable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 782FB0982AB4B6C500BC8C12 /* Toastable.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 */; }; @@ -44,6 +45,7 @@ 78274D992A9E26DF00AD4F50 /* DiaryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryCell.swift; sourceTree = ""; }; 78274DA02A9E3E8E00AD4F50 /* DiaryModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryModel.swift; sourceTree = ""; }; 78274DA32A9F3F0A00AD4F50 /* DateFormatter+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+.swift"; sourceTree = ""; }; + 782FB0982AB4B6C500BC8C12 /* Toastable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toastable.swift; sourceTree = ""; }; 784F30C82AB2F88F009A895B /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = ""; }; 784F30CA2AB2FE87009A895B /* DecodingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingManager.swift; sourceTree = ""; }; 784F30CD2AB30072009A895B /* DecodingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingError.swift; sourceTree = ""; }; @@ -182,6 +184,7 @@ isa = PBXGroup; children = ( 9C1529102AAE140800F3203E /* Shareable.swift */, + 782FB0982AB4B6C500BC8C12 /* Toastable.swift */, ); path = Protocol; sourceTree = ""; @@ -376,6 +379,7 @@ 78274DA42A9F3F0A00AD4F50 /* DateFormatter+.swift in Sources */, 9C5C42F42AB36F6B004FF07A /* CacheStore.swift in Sources */, C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */, + 782FB0992AB4B6C500BC8C12 /* Toastable.swift in Sources */, 9C4621EC2AB06890004ED11A /* PersistentContainer.swift in Sources */, 784F30C92AB2F88F009A895B /* Location.swift in Sources */, 784F30CB2AB2FE87009A895B /* DecodingManager.swift in Sources */, diff --git a/Diary/Controller/DiaryDetailViewController.swift b/Diary/Controller/DiaryDetailViewController.swift index 750588457..261656e91 100644 --- a/Diary/Controller/DiaryDetailViewController.swift +++ b/Diary/Controller/DiaryDetailViewController.swift @@ -29,6 +29,7 @@ final class DiaryDetailViewController: UIViewController, Shareable { override func viewDidLoad() { super.viewDidLoad() configure() + configureToast() fetchWeather() } @@ -183,6 +184,38 @@ private extension DiaryDetailViewController { } } +extension DiaryDetailViewController: Toastable { + func configureToast() { + APIKey.delegate = self + } + + func showToast(message: String) { + let toastLabel = UILabel(frame: CGRect( + x: self.view.frame.size.width / 2 - 100, + y: self.view.frame.size.height / 2 - 35, + width: 200, + height: 70 + )) + + toastLabel.backgroundColor = UIColor.systemGray + toastLabel.textColor = UIColor.white + toastLabel.font = UIFont.preferredFont(forTextStyle: .body) + toastLabel.textAlignment = .center + toastLabel.text = message + toastLabel.alpha = 1.0 + toastLabel.layer.cornerRadius = 10 + toastLabel.clipsToBounds = true + toastLabel.numberOfLines = 0 + + view.addSubview(toastLabel) + UIView.animate(withDuration: 5.0, delay: 0.1, options: .curveEaseOut, animations: { + toastLabel.alpha = 0.0 + }, completion: { _ in + toastLabel.removeFromSuperview() + }) + } +} + private extension DiaryDetailViewController { func fetchWeather() { guard let latitude, let longitude else { diff --git a/Diary/Network/Model/URLComponents.swift b/Diary/Network/Model/URLComponents.swift index e73506597..308237ef9 100644 --- a/Diary/Network/Model/URLComponents.swift +++ b/Diary/Network/Model/URLComponents.swift @@ -47,11 +47,13 @@ enum Query { } enum APIKey { + static var delegate: Toastable? static var weather: String { guard let file = Bundle.main.path(forResource: "WeatherInfo", ofType: "plist"), let resource = NSDictionary(contentsOfFile: file), let key = resource["API_KEY"] as? String else { - fatalError("⛔️ API KEY를 가져오는데 실패하였습니다.") + delegate?.showToast(message: "⛔️ API KEY를 가져오는데 실패하였습니다.") + return "⛔️ API KEY를 가져오는데 실패하였습니다." } return key diff --git a/Diary/Protocol/Toastable.swift b/Diary/Protocol/Toastable.swift new file mode 100644 index 000000000..b21b9f088 --- /dev/null +++ b/Diary/Protocol/Toastable.swift @@ -0,0 +1,10 @@ +// +// Toastable.swift +// Diary +// +// Created by hoon, karen on 2023/09/16. +// + +protocol Toastable { + func showToast(message: String) +}