Skip to content

Commit dd9c28f

Browse files
committed
(#161) feat: 캐시데이터 생성하기
1 parent 4dd2b90 commit dd9c28f

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

Diff for: WithBuddy.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
8A73D679273A61EC001D5184 /* BuddyChoiceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A73D678273A61EC001D5184 /* BuddyChoiceViewController.swift */; };
5050
8A73D67E273A6C4B001D5184 /* BuddyChoiceViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A73D67D273A6C4B001D5184 /* BuddyChoiceViewModel.swift */; };
5151
8A8EA0C8274CAF4100F1BDFD /* UserUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A8EA0C7274CAF4100F1BDFD /* UserUseCase.swift */; };
52+
8A97318E2756273E00B18D0B /* PictureUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A97318D2756273E00B18D0B /* PictureUseCase.swift */; };
5253
8AD6691F2744D94B00158E1A /* BuddyCustomViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AD6691E2744D94B00158E1A /* BuddyCustomViewModel.swift */; };
5354
8AD669212744F12300158E1A /* ImageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AD669202744F12300158E1A /* ImageCollectionViewCell.swift */; };
5455
8AF3152727461A8800BDDF85 /* CheckableInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF3152627461A8800BDDF85 /* CheckableInfo.swift */; };
@@ -159,6 +160,7 @@
159160
8A73D678273A61EC001D5184 /* BuddyChoiceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuddyChoiceViewController.swift; sourceTree = "<group>"; };
160161
8A73D67D273A6C4B001D5184 /* BuddyChoiceViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuddyChoiceViewModel.swift; sourceTree = "<group>"; };
161162
8A8EA0C7274CAF4100F1BDFD /* UserUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserUseCase.swift; sourceTree = "<group>"; };
163+
8A97318D2756273E00B18D0B /* PictureUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PictureUseCase.swift; sourceTree = "<group>"; };
162164
8AD6691E2744D94B00158E1A /* BuddyCustomViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuddyCustomViewModel.swift; sourceTree = "<group>"; };
163165
8AD669202744F12300158E1A /* ImageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewCell.swift; sourceTree = "<group>"; };
164166
8AF3152627461A8800BDDF85 /* CheckableInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckableInfo.swift; sourceTree = "<group>"; };
@@ -285,6 +287,7 @@
285287
F7B69B89273398C4005D2F32 /* CalendarUseCase.swift */,
286288
BB1936D2274B8F50007EF21A /* PurposeUseCase.swift */,
287289
8A8EA0C7274CAF4100F1BDFD /* UserUseCase.swift */,
290+
8A97318D2756273E00B18D0B /* PictureUseCase.swift */,
288291
);
289292
path = UseCases;
290293
sourceTree = "<group>";
@@ -939,6 +942,7 @@
939942
854AA76427338C2F00663911 /* ListTableViewCell.swift in Sources */,
940943
F7E8ABC5273BB814005F8306 /* GatheringDetailViewController.swift in Sources */,
941944
8A07DF6A2743C20A008F6E58 /* GatheringEditViewController.swift in Sources */,
945+
8A97318E2756273E00B18D0B /* PictureUseCase.swift in Sources */,
942946
8A8EA0C8274CAF4100F1BDFD /* UserUseCase.swift in Sources */,
943947
BB2D25C2273B901600E7BF35 /* BuddyEntity+CoreDataClass.swift in Sources */,
944948
85D262F2273CE7D6000190B8 /* BlackTitleLabel.swift in Sources */,

Diff for: WithBuddy/Domain/UseCases/PictureUseCase.swift

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// PictureUseCase.swift
3+
// WithBuddy
4+
//
5+
// Created by Inwoo Park on 2021/11/30.
6+
//
7+
8+
import Foundation
9+
10+
final class PictureUseCase {
11+
12+
func savePicture(sourceUrl: URL) -> URL? {
13+
guard let path = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first else { return nil }
14+
var destinationUrl = URL(fileURLWithPath: path)
15+
destinationUrl.appendPathComponent(sourceUrl.lastPathComponent)
16+
17+
let fileManager = FileManager()
18+
do {
19+
try fileManager.moveItem(at: sourceUrl, to: destinationUrl)
20+
} catch {
21+
return nil
22+
}
23+
24+
return destinationUrl
25+
}
26+
27+
}

Diff for: WithBuddy/Presentation/Common/View/ImageTextCollectionViewCell.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ final class ImageTextCollectionViewCell: UICollectionViewCell {
2323
}
2424

2525
func update(image: UIImage?, text: String, check: Bool?) {
26-
guard let image = image else {
27-
return
28-
}
26+
guard let image = image else { return }
2927
self.backgroundColor = .backgroundPurple
3028
self.image.image = image
3129
self.textLabel.text = text
@@ -38,9 +36,7 @@ final class ImageTextCollectionViewCell: UICollectionViewCell {
3836
}
3937

4038
func update(image: UIImage?, text: String) {
41-
guard let image = image else {
42-
return
43-
}
39+
guard let image = image else { return }
4440
self.backgroundColor = .backgroundPurple
4541
self.image.image = image
4642
self.textLabel.text = text

Diff for: WithBuddy/Presentation/Common/View/PictureCollectionViewCell.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ final class PictureCollectionViewCell: UICollectionViewCell {
2222
}
2323

2424
func configure(url: URL) {
25-
guard let data = try? Data(contentsOf: url) else {
26-
return
27-
}
25+
guard let data = try? Data(contentsOf: url) else { return }
2826
photoImage.image = UIImage(data: data)
2927
}
3028

Diff for: WithBuddy/Presentation/Register/View/RegisterViewController.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,7 @@ extension RegisterViewController: UITextViewDelegate {
687687
extension RegisterViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
688688

689689
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
690-
guard let url = info[UIImagePickerController.InfoKey.imageURL] as? URL else {
691-
return
692-
}
690+
guard let url = info[UIImagePickerController.InfoKey.imageURL] as? URL else { return }
693691
self.registerViewModel.didPicturePicked(url)
694692
dismiss(animated: true, completion: nil)
695693
}

Diff for: WithBuddy/Presentation/Register/ViewModel/RegisterViewModel.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ final class RegisterViewModel {
4141
private var buddyUseCase = BuddyUseCase(coreDataManager: CoreDataManager.shared)
4242
private var gatheringUseCase = GatheringUseCase(coreDataManager: CoreDataManager.shared)
4343
private var purposeUseCase = PurposeUseCase(coreDataManager: CoreDataManager.shared)
44+
private var pictureUseCase = PictureUseCase()
4445

4546
init() {
4647
self.purposeList = PurposeCategory.allCases.map({
@@ -73,7 +74,8 @@ final class RegisterViewModel {
7374
}
7475

7576
func didPicturePicked(_ picture: URL) {
76-
self.pictures.insert(picture, at: Int.zero)
77+
guard let url = pictureUseCase.savePicture(sourceUrl: picture) else { return }
78+
self.pictures.insert(url, at: Int.zero)
7779
}
7880

7981
func didPictureDeleteTouched(in idx: Int) {

0 commit comments

Comments
 (0)