Skip to content

Commit

Permalink
feat: Image Cache 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhyunm committed Sep 13, 2023
1 parent cd2355e commit 06f7a98
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 71 deletions.
58 changes: 41 additions & 17 deletions Diary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
63E527352A9D7EBF0000FBA6 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */; };
63E527372A9D87660000FBA6 /* DiaryListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527362A9D87660000FBA6 /* DiaryListTableViewCell.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 */; };
BABBDB342AA6D05A00D8D50B /* ShareDisplayable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BABBDB332AA6D05A00D8D50B /* ShareDisplayable.swift */; };
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 */; };
BAECB2DD2AB187D6006B4A46 /* ImageCachingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAECB2DC2AB187D6006B4A46 /* ImageCachingManager.swift */; };
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 @@ -46,21 +46,21 @@
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>"; };
63BB62812A9F109400524DCB /* DecodingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingManager.swift; sourceTree = "<group>"; };
63BB62B02AA181BE00524DCB /* Diary+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Diary+CoreDataClass.swift"; sourceTree = SOURCE_ROOT; };
63BB62B12AA181BE00524DCB /* Diary+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Diary+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; };
63BB62B02AA181BE00524DCB /* Diary+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Diary+CoreDataClass.swift"; path = "Diary/Model/CoreData/Diary+CoreDataClass.swift"; sourceTree = SOURCE_ROOT; };
63BB62B12AA181BE00524DCB /* Diary+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Diary+CoreDataProperties.swift"; path = "Diary/Model/CoreData/Diary+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; };
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 /* 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>"; };
BABBDAE42A9F13A200D8D50B /* DecodingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingError.swift; sourceTree = "<group>"; };
BABBDB332AA6D05A00D8D50B /* ShareDisplayable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareDisplayable.swift; sourceTree = "<group>"; };
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>"; };
BAECB2CE2AB15742006B4A46 /* Key.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Key.plist; 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>"; };
BAECB2DC2AB187D6006B4A46 /* ImageCachingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCachingManager.swift; 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 @@ -120,12 +120,14 @@
path = Protocol;
sourceTree = "<group>";
};
63BB62B62AA185E700524DCB /* DataManager */ = {
63BB62B62AA185E700524DCB /* CoreData */ = {
isa = PBXGroup;
children = (
63BB62B02AA181BE00524DCB /* Diary+CoreDataClass.swift */,
63BB62B12AA181BE00524DCB /* Diary+CoreDataProperties.swift */,
63BB62B42AA182AA00524DCB /* CoreDataManager.swift */,
);
path = DataManager;
path = CoreData;
sourceTree = "<group>";
};
63E5273C2A9ECD5A0000FBA6 /* App */ = {
Expand All @@ -140,13 +142,10 @@
63E5273D2A9ECD660000FBA6 /* Model */ = {
isa = PBXGroup;
children = (
63BB62B02AA181BE00524DCB /* Diary+CoreDataClass.swift */,
63BB62B12AA181BE00524DCB /* Diary+CoreDataProperties.swift */,
BA1A55EA2A9D84AF0012C89D /* DiaryEntity.swift */,
63BB62812A9F109400524DCB /* DecodingManager.swift */,
63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */,
63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */,
632F74F12AB14D8D003E1B97 /* WeatherResult.swift */,
BAECB2DA2AB1877C006B4A46 /* DTO */,
63BB62B62AA185E700524DCB /* CoreData */,
BAECB2DB2AB187AB006B4A46 /* Namespace */,
BAECB2DE2AB18A17006B4A46 /* ImageCache */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -187,10 +186,35 @@
path = Error;
sourceTree = "<group>";
};
BAECB2DA2AB1877C006B4A46 /* DTO */ = {
isa = PBXGroup;
children = (
632F74F12AB14D8D003E1B97 /* WeatherResult.swift */,
63BB62812A9F109400524DCB /* DecodingManager.swift */,
);
path = DTO;
sourceTree = "<group>";
};
BAECB2DB2AB187AB006B4A46 /* Namespace */ = {
isa = PBXGroup;
children = (
63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */,
63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */,
);
path = Namespace;
sourceTree = "<group>";
};
BAECB2DE2AB18A17006B4A46 /* ImageCache */ = {
isa = PBXGroup;
children = (
BAECB2DC2AB187D6006B4A46 /* ImageCachingManager.swift */,
);
path = ImageCache;
sourceTree = "<group>";
};
C739AE18284DF28600741E8F = {
isa = PBXGroup;
children = (
BAECB2CE2AB15742006B4A46 /* Key.plist */,
63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */,
C739AE23284DF28600741E8F /* Diary */,
C739AE22284DF28600741E8F /* Products */,
Expand All @@ -212,7 +236,6 @@
children = (
632F74EE2AB14CF3003E1B97 /* Network */,
636B19AA2AA6C5C200B5242D /* Protocol */,
63BB62B62AA185E700524DCB /* DataManager */,
63E5273E2A9ECD800000FBA6 /* Extension */,
63E5273D2A9ECD660000FBA6 /* Model */,
BABBDAE62A9F13AE00D8D50B /* Error */,
Expand All @@ -221,6 +244,7 @@
63E5273C2A9ECD5A0000FBA6 /* App */,
C739AE30284DF28600741E8F /* Assets.xcassets */,
C739AE35284DF28600741E8F /* Info.plist */,
BAECB2CE2AB15742006B4A46 /* Key.plist */,
C739AE2D284DF28600741E8F /* Diary.xcdatamodeld */,
BAECB2D82AB18611006B4A46 /* DiaryV2.xcmappingmodel */,
);
Expand Down Expand Up @@ -348,6 +372,7 @@
C739AE25284DF28600741E8F /* AppDelegate.swift in Sources */,
C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */,
636B19AC2AA6C5E900B5242D /* AlertDisplayble.swift in Sources */,
BAECB2DD2AB187D6006B4A46 /* ImageCachingManager.swift in Sources */,
63BB62822A9F109400524DCB /* DecodingManager.swift in Sources */,
632F74F22AB14D8D003E1B97 /* WeatherResult.swift in Sources */,
BA1A55ED2A9D90810012C89D /* DateFormatter+.swift in Sources */,
Expand All @@ -363,7 +388,6 @@
BABBDB342AA6D05A00D8D50B /* ShareDisplayable.swift in Sources */,
63B12BB02AAD9D3400D614A6 /* ButtonNamespace.swift in Sources */,
63BB62B32AA181BE00524DCB /* Diary+CoreDataProperties.swift in Sources */,
BA1A55EB2A9D84AF0012C89D /* DiaryEntity.swift in Sources */,
63B12BAE2AAD9C9000D614A6 /* AlertNamespace.swift in Sources */,
63BB62B22AA181BE00524DCB /* Diary+CoreDataClass.swift in Sources */,
632F74F42AB14DBC003E1B97 /* APIError.swift in Sources */,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions Diary/Model/DTO/DecodingManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// DecodingManager.swift
// Diary
//
// Created by Maxhyunm, Hamg on 2023/08/30.
//

import UIKit

final class DecodingManager {
static func decodeData<T: Decodable>(from data: Data) throws -> T {
let decoder = JSONDecoder()

guard let decodedData = try? decoder.decode(T.self, from: data) else {
throw DecodingError.decodingFailure
}

return decodedData
}
}
File renamed without changes.
34 changes: 0 additions & 34 deletions Diary/Model/DecodingManager.swift

This file was deleted.

19 changes: 0 additions & 19 deletions Diary/Model/DiaryEntity.swift

This file was deleted.

14 changes: 14 additions & 0 deletions Diary/Model/ImageCache/ImageCachingManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// ImageCachingManager.swift
// Diary
//
// Created by Maxhyunm, Hamg on 2023/09/13.
//

import UIKit

class ImageCachingManager {
static let shared = NSCache<NSString, UIImage>()

private init() {}
}
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion Diary/View/DiaryListTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ final class DiaryListTableViewCell: UITableViewCell {
bodyLabel.text = body

if let icon {
setImageView(icon: icon)
guard let cachedImage = ImageCachingManager.shared.object(forKey: NSString(string: icon)) else {
setImageView(icon: icon)
return
}
weatherIconImageView.image = cachedImage
}
}

Expand All @@ -103,6 +107,7 @@ final class DiaryListTableViewCell: UITableViewCell {
case .success(let data):
guard let image = UIImage(data: data) else { return }
DispatchQueue.main.async {
ImageCachingManager.shared.setObject(image, forKey: NSString(string: icon))
self?.weatherIconImageView.image = image
}
case .failure(let error):
Expand Down

0 comments on commit 06f7a98

Please sign in to comment.