Skip to content

Commit

Permalink
✴️ feat: showToast 메서드 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoon94 committed Sep 15, 2023
1 parent 7d36fcf commit 336190a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Diary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -44,6 +45,7 @@
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>"; };
782FB0982AB4B6C500BC8C12 /* Toastable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toastable.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>"; };
Expand Down Expand Up @@ -182,6 +184,7 @@
isa = PBXGroup;
children = (
9C1529102AAE140800F3203E /* Shareable.swift */,
782FB0982AB4B6C500BC8C12 /* Toastable.swift */,
);
path = Protocol;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
33 changes: 33 additions & 0 deletions Diary/Controller/DiaryDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class DiaryDetailViewController: UIViewController, Shareable {
override func viewDidLoad() {
super.viewDidLoad()
configure()
configureToast()
fetchWeather()
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion Diary/Network/Model/URLComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Diary/Protocol/Toastable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Toastable.swift
// Diary
//
// Created by hoon, karen on 2023/09/16.
//

protocol Toastable {
func showToast(message: String)
}

0 comments on commit 336190a

Please sign in to comment.