Skip to content

Commit

Permalink
feat: Weather Main 값과 Icon 값 저장 및 아이콘 이미지 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhyunm committed Sep 13, 2023
1 parent e7fc76e commit cd2355e
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Diary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
BABBDB362AAD904100D8D50B /* CoreDataError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BABBDB352AAD904100D8D50B /* CoreDataError.swift */; };
BAECB2CF2AB15742006B4A46 /* Key.plist in Resources */ = {isa = PBXBuildFile; fileRef = BAECB2CE2AB15742006B4A46 /* Key.plist */; };
BAECB2D12AB157CB006B4A46 /* NetworkConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAECB2D02AB157CB006B4A46 /* NetworkConfiguration.swift */; };
BAECB2D92AB18611006B4A46 /* DiaryV2.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = BAECB2D82AB18611006B4A46 /* DiaryV2.xcmappingmodel */; };
C739AE25284DF28600741E8F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE24284DF28600741E8F /* AppDelegate.swift */; };
C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE26284DF28600741E8F /* SceneDelegate.swift */; };
C739AE29284DF28600741E8F /* DiaryListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE28284DF28600741E8F /* DiaryListViewController.swift */; };
Expand All @@ -41,7 +42,6 @@
632F74F12AB14D8D003E1B97 /* WeatherResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherResult.swift; sourceTree = "<group>"; };
632F74F32AB14DBC003E1B97 /* APIError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIError.swift; sourceTree = "<group>"; };
632F74F72AB17E05003E1B97 /* Diary V2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Diary V2.xcdatamodel"; sourceTree = "<group>"; };
632F74F82AB17E85003E1B97 /* DiaryV2.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; name = DiaryV2.xcmappingmodel; path = "/Users/a1/ios-diary/DiaryV2.xcmappingmodel"; sourceTree = "<absolute>"; };
636B19AB2AA6C5E900B5242D /* AlertDisplayble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertDisplayble.swift; sourceTree = "<group>"; };
63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertNamespace.swift; sourceTree = "<group>"; };
63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonNamespace.swift; sourceTree = "<group>"; };
Expand All @@ -60,6 +60,7 @@
BABBDB352AAD904100D8D50B /* CoreDataError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataError.swift; sourceTree = "<group>"; };
BAECB2CE2AB15742006B4A46 /* Key.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Key.plist; sourceTree = "<group>"; };
BAECB2D02AB157CB006B4A46 /* NetworkConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConfiguration.swift; sourceTree = "<group>"; };
BAECB2D82AB18611006B4A46 /* DiaryV2.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = DiaryV2.xcmappingmodel; sourceTree = "<group>"; };
C739AE21284DF28600741E8F /* Diary.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Diary.app; sourceTree = BUILT_PRODUCTS_DIR; };
C739AE24284DF28600741E8F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C739AE26284DF28600741E8F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -192,7 +193,6 @@
BAECB2CE2AB15742006B4A46 /* Key.plist */,
63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */,
C739AE23284DF28600741E8F /* Diary */,
632F74F82AB17E85003E1B97 /* DiaryV2.xcmappingmodel */,
C739AE22284DF28600741E8F /* Products */,
26661DE0A3935A6B3B8FED0D /* Pods */,
524E42FF436814999DB2C64E /* Frameworks */,
Expand Down Expand Up @@ -222,6 +222,7 @@
C739AE30284DF28600741E8F /* Assets.xcassets */,
C739AE35284DF28600741E8F /* Info.plist */,
C739AE2D284DF28600741E8F /* Diary.xcdatamodeld */,
BAECB2D82AB18611006B4A46 /* DiaryV2.xcmappingmodel */,
);
path = Diary;
sourceTree = "<group>";
Expand Down Expand Up @@ -355,6 +356,7 @@
BAECB2D12AB157CB006B4A46 /* NetworkConfiguration.swift in Sources */,
63BB62B52AA182AA00524DCB /* CoreDataManager.swift in Sources */,
632F74F02AB14D2C003E1B97 /* NetworkManager.swift in Sources */,
BAECB2D92AB18611006B4A46 /* DiaryV2.xcmappingmodel in Sources */,
63E527392A9D97160000FBA6 /* DiaryDetailViewController.swift in Sources */,
BABBDAE52A9F13A200D8D50B /* DecodingError.swift in Sources */,
BABBDB362AAD904100D8D50B /* CoreDataError.swift in Sources */,
Expand Down
3 changes: 0 additions & 3 deletions Diary.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Diary/Controller/DiaryDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ extension DiaryDetailViewController {
case .success(let data):
do {
let decodingData: WeatherResult = try DecodingManager.decodeData(from: data)
print(decodingData.weather.first!.main) // TODO: 마이그레이션 후 삭제
guard let weatherMain = decodingData.weather.first?.main,
let weatherIcon = decodingData.weather.first?.icon else {
return
}
self.diary.weatherMain = weatherMain
self.diary.weatherIcon = weatherIcon
} catch {
DispatchQueue.main.async {
let confirmAction = UIAlertAction(title: ButtonNamespace.confirm, style: .default)
Expand Down
2 changes: 1 addition & 1 deletion Diary/Controller/DiaryListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extension DiaryListViewController: UITableViewDataSource {
}
let date = dateFormatter.formatToString(from: createdAt, with: "YYYY년 MM월 dd일")

cell.setModel(title: title, date: date, body: body)
cell.setModel(title: title, date: date, body: body, icon: diaryEntity.weatherIcon)

return cell
}
Expand Down
94 changes: 94 additions & 0 deletions Diary/DiaryV2.xcmappingmodel/xcmapping.xml

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions Diary/View/DiaryListTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class DiaryListTableViewCell: UITableViewCell {
label.translatesAutoresizingMaskIntoConstraints = false
label.font = .preferredFont(forTextStyle: .callout)
label.setContentCompressionResistancePriority(.required, for: .horizontal)
label.setContentHuggingPriority(.required, for: .horizontal)

return label
}()
Expand All @@ -39,6 +40,7 @@ final class DiaryListTableViewCell: UITableViewCell {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
imageView.setContentHuggingPriority(.required, for: .horizontal)

return imageView
}()
Expand Down Expand Up @@ -73,22 +75,26 @@ final class DiaryListTableViewCell: UITableViewCell {
dateLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5),

weatherIconImageView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8),
weatherIconImageView.leadingAnchor.constraint(equalTo: dateLabel.trailingAnchor, constant: 4),
weatherIconImageView.leadingAnchor.constraint(equalTo: dateLabel.trailingAnchor, constant: 15),
weatherIconImageView.centerYAnchor.constraint(equalTo: dateLabel.centerYAnchor),
weatherIconImageView.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.05),
weatherIconImageView.heightAnchor.constraint(equalTo: weatherIconImageView.widthAnchor),

bodyLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8),
bodyLabel.leadingAnchor.constraint(equalTo: weatherIconImageView.trailingAnchor, constant: 4),
bodyLabel.leadingAnchor.constraint(equalTo: weatherIconImageView.trailingAnchor, constant: 15),
bodyLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -40),
bodyLabel.centerYAnchor.constraint(equalTo: dateLabel.centerYAnchor)
])
}

func setModel(title: String, date: String, body: String) {
func setModel(title: String, date: String, body: String, icon: String?) {
titleLabel.text = title
dateLabel.text = date
bodyLabel.text = body

if let icon {
setImageView(icon: icon)
}
}

func setImageView(icon: String) {
Expand Down

0 comments on commit cd2355e

Please sign in to comment.