Skip to content

Commit

Permalink
feat: Migration 진행, ImageView생성
Browse files Browse the repository at this point in the history
  • Loading branch information
hemg2 committed Sep 13, 2023
1 parent f21b2b8 commit e7fc76e
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Diary+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extension Diary {
@NSManaged public var title: String?
@NSManaged public var body: String?
@NSManaged public var createdAt: Date?
@NSManaged public var weatherIcon: String?
@NSManaged public var weatherMain: String?
}

extension Diary: Identifiable {
Expand Down
14 changes: 9 additions & 5 deletions Diary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
63BB62B52AA182AA00524DCB /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63BB62B42AA182AA00524DCB /* CoreDataManager.swift */; };
63E527352A9D7EBF0000FBA6 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */; };
63E527372A9D87660000FBA6 /* DiaryListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527362A9D87660000FBA6 /* DiaryListTableViewCell.swift */; };
63E527392A9D97160000FBA6 /* DiaryDetailViewContoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527382A9D97160000FBA6 /* DiaryDetailViewContoller.swift */; };
63E527392A9D97160000FBA6 /* DiaryDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527382A9D97160000FBA6 /* DiaryDetailViewController.swift */; };
BA1A55EB2A9D84AF0012C89D /* DiaryEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1A55EA2A9D84AF0012C89D /* DiaryEntity.swift */; };
BA1A55ED2A9D90810012C89D /* DateFormatter+.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1A55EC2A9D90810012C89D /* DateFormatter+.swift */; };
BABBDAE52A9F13A200D8D50B /* DecodingError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BABBDAE42A9F13A200D8D50B /* DecodingError.swift */; };
Expand All @@ -40,6 +40,8 @@
632F74EF2AB14D2C003E1B97 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
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 @@ -49,7 +51,7 @@
63BB62B42AA182AA00524DCB /* CoreDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
63E527362A9D87660000FBA6 /* DiaryListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryListTableViewCell.swift; sourceTree = "<group>"; };
63E527382A9D97160000FBA6 /* DiaryDetailViewContoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDetailViewContoller.swift; sourceTree = "<group>"; };
63E527382A9D97160000FBA6 /* DiaryDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDetailViewController.swift; sourceTree = "<group>"; };
7B86D20E06F2B506DECF94F6 /* Pods-Diary.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Diary.release.xcconfig"; path = "Target Support Files/Pods-Diary/Pods-Diary.release.xcconfig"; sourceTree = "<group>"; };
BA1A55EA2A9D84AF0012C89D /* DiaryEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryEntity.swift; sourceTree = "<group>"; };
BA1A55EC2A9D90810012C89D /* DateFormatter+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -160,7 +162,7 @@
isa = PBXGroup;
children = (
C739AE28284DF28600741E8F /* DiaryListViewController.swift */,
63E527382A9D97160000FBA6 /* DiaryDetailViewContoller.swift */,
63E527382A9D97160000FBA6 /* DiaryDetailViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -190,6 +192,7 @@
BAECB2CE2AB15742006B4A46 /* Key.plist */,
63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */,
C739AE23284DF28600741E8F /* Diary */,
632F74F82AB17E85003E1B97 /* DiaryV2.xcmappingmodel */,
C739AE22284DF28600741E8F /* Products */,
26661DE0A3935A6B3B8FED0D /* Pods */,
524E42FF436814999DB2C64E /* Frameworks */,
Expand Down Expand Up @@ -352,7 +355,7 @@
BAECB2D12AB157CB006B4A46 /* NetworkConfiguration.swift in Sources */,
63BB62B52AA182AA00524DCB /* CoreDataManager.swift in Sources */,
632F74F02AB14D2C003E1B97 /* NetworkManager.swift in Sources */,
63E527392A9D97160000FBA6 /* DiaryDetailViewContoller.swift in Sources */,
63E527392A9D97160000FBA6 /* DiaryDetailViewController.swift in Sources */,
BABBDAE52A9F13A200D8D50B /* DecodingError.swift in Sources */,
BABBDB362AAD904100D8D50B /* CoreDataError.swift in Sources */,
BABBDB342AA6D05A00D8D50B /* ShareDisplayable.swift in Sources */,
Expand Down Expand Up @@ -578,9 +581,10 @@
C739AE2D284DF28600741E8F /* Diary.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
632F74F72AB17E05003E1B97 /* Diary V2.xcdatamodel */,
C739AE2E284DF28600741E8F /* Diary.xcdatamodel */,
);
currentVersion = C739AE2E284DF28600741E8F /* Diary.xcdatamodel */;
currentVersion = 632F74F72AB17E05003E1B97 /* Diary V2.xcdatamodel */;
path = Diary.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
3 changes: 3 additions & 0 deletions Diary.xcworkspace/contents.xcworkspacedata

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

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// DiaryDetailViewContoller.swift
// DiaryDetailViewController.swift
// Diary
//
// Created by Maxhyunm, Hamg on 2023/08/29.
//

import UIKit

final class DiaryDetailViewContoller: UIViewController, AlertDisplayable, ShareDisplayable {
final class DiaryDetailViewController: UIViewController, AlertDisplayable, ShareDisplayable {
private let textView: UITextView = {
let textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -132,7 +132,7 @@ final class DiaryDetailViewContoller: UIViewController, AlertDisplayable, ShareD
}
}

extension DiaryDetailViewContoller {
extension DiaryDetailViewController {
@objc private func keyboardWillShow(_ notification: Notification) {
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey]
as? CGRect else { return }
Expand Down Expand Up @@ -167,7 +167,7 @@ extension DiaryDetailViewContoller {
}
}

extension DiaryDetailViewContoller: UITextViewDelegate {
extension DiaryDetailViewController: UITextViewDelegate {
func textViewDidEndEditing(_ textView: UITextView) {
let contents = textView.text.split(separator: "\n")
guard !contents.isEmpty else { return }
Expand Down Expand Up @@ -201,7 +201,7 @@ extension DiaryDetailViewContoller: UITextViewDelegate {
}
}

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

Expand Down
4 changes: 2 additions & 2 deletions Diary/Controller/DiaryListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class DiaryListViewController: UIViewController {
private func setupNavigationBarButton() {
let addDiary = UIAction(image: UIImage(systemName: "plus")) { [weak self] _ in
guard let self else { return }
let createDiaryView = DiaryDetailViewContoller(latitude: latitude, longitude: longitude)
let createDiaryView = DiaryDetailViewController(latitude: self.latitude, longitude: self.longitude)
self.navigationController?.pushViewController(createDiaryView, animated: true)
}

Expand Down Expand Up @@ -119,7 +119,7 @@ extension DiaryListViewController: UITableViewDelegate, ShareDisplayable {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let diaryToEdit = diaryList[indexPath.row]
let createVC = DiaryDetailViewContoller(diaryToEdit)
let createVC = DiaryDetailViewController(diaryToEdit)

navigationController?.pushViewController(createVC, animated: true)
}
Expand Down
2 changes: 1 addition & 1 deletion Diary/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>
11 changes: 11 additions & 0 deletions Diary/Diary.xcdatamodeld/Diary V2.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21279" systemVersion="22D49" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Diary" representedClassName="Diary" syncable="YES">
<attribute name="body" optional="YES" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="title" optional="YES" attributeType="String"/>
<attribute name="weatherIcon" optional="YES" attributeType="String"/>
<attribute name="weatherMain" optional="YES" attributeType="String"/>
</entity>
</model>
31 changes: 30 additions & 1 deletion Diary/View/DiaryListTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ final class DiaryListTableViewCell: UITableViewCell {
return label
}()

private let weatherIconImageView: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)

return imageView
}()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupLabel()
Expand All @@ -48,6 +56,7 @@ final class DiaryListTableViewCell: UITableViewCell {
private func setupLabel() {
contentView.addSubview(titleLabel)
contentView.addSubview(dateLabel)
contentView.addSubview(weatherIconImageView)
contentView.addSubview(bodyLabel)
}

Expand All @@ -63,8 +72,14 @@ final class DiaryListTableViewCell: UITableViewCell {
dateLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20),
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.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: dateLabel.trailingAnchor, constant: 4),
bodyLabel.leadingAnchor.constraint(equalTo: weatherIconImageView.trailingAnchor, constant: 4),
bodyLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -40),
bodyLabel.centerYAnchor.constraint(equalTo: dateLabel.centerYAnchor)
])
Expand All @@ -75,4 +90,18 @@ final class DiaryListTableViewCell: UITableViewCell {
dateLabel.text = date
bodyLabel.text = body
}

func setImageView(icon: String) {
NetworkManager.shared.fetchData(NetworkConfiguration.weatherIcon(id: icon)) { [weak self] result in
switch result {
case .success(let data):
guard let image = UIImage(data: data) else { return }
DispatchQueue.main.async {
self?.weatherIconImageView.image = image
}
case .failure(let error):
print(error)
}
}
}
}
94 changes: 94 additions & 0 deletions DiaryV2.xcmappingmodel/xcmapping.xml

Large diffs are not rendered by default.

0 comments on commit e7fc76e

Please sign in to comment.