Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ public final class RealmClimbRecordRepositoryImpl: ClimbRecordRepository {
try realm.write {
realm.delete(record.images)
if let mountain = record.mountain {
realm.delete(mountain)
let otherRecords = realm.objects(ClimbRecordRealm.self)
.filter("mountain == %@", mountain)
if otherRecords.count <= 1 {
realm.delete(mountain)
}
}
realm.delete(record.timeLog)
realm.delete(record)
Expand Down
25 changes: 25 additions & 0 deletions Domain/Sources/Entity/ImageItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ImageItem.swift
// Domain
//
// Created by 김영훈 on 1/31/26.
//

import Foundation

public struct ImageItem: Hashable {
let id = UUID()
public let data: Data

public init(data: Data) {
self.data = data
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}

public static func == (lhs: ImageItem, rhs: ImageItem) -> Bool {
return lhs.id == rhs.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ extension AddClimbRecordViewController: UITableViewDelegate {
private func applySnapshot(mountains: [Mountain]) {
var snapshot = NSDiffableDataSourceSnapshot<Section, Mountain>()
snapshot.appendSections([.main])
snapshot.appendItems(mountains)
snapshot.appendItems(mountains.uniq(by: \.id))
dataSource.apply(snapshot, animatingDifferences: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,23 @@ extension ClimbRecordDetailViewController {
case main
}

private func createRegistration() -> UICollectionView.CellRegistration<ImageCollectionViewCell, Data> {
return UICollectionView.CellRegistration<ImageCollectionViewCell, Data> { cell, indexPath, item in
private func createRegistration() -> UICollectionView.CellRegistration<ImageCollectionViewCell, ImageItem> {
return UICollectionView.CellRegistration<ImageCollectionViewCell, ImageItem> { cell, indexPath, item in
cell.setImage(imageData: item)
}
}

private func createDataSource() -> UICollectionViewDiffableDataSource<Section, Data> {
private func createDataSource() -> UICollectionViewDiffableDataSource<Section, ImageItem> {
let registration = createRegistration()
return UICollectionViewDiffableDataSource<Section, Data>(collectionView: mainView.imageCollectionView) { collectionView, indexPath, item in
return UICollectionViewDiffableDataSource<Section, ImageItem>(collectionView: mainView.imageCollectionView) { collectionView, indexPath, item in
collectionView.dequeueConfiguredReusableCell(using: registration, for: indexPath, item: item)
}
}

private func applySnapshot(images: [Data]) {
var snapshot = NSDiffableDataSourceSnapshot<Section, Data>()
private func applySnapshot(images: [ImageItem]) {
var snapshot = NSDiffableDataSourceSnapshot<Section, ImageItem>()
snapshot.appendSections(Section.allCases)
snapshot.appendItems(images)
snapshot.appendItems(images.uniq(by: \.self))
dataSource.apply(snapshot, animatingDifferences: true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {
let timelineButtonTitle: AnyPublisher<String, Never>
let presentPhotoActionSheet: AnyPublisher<Bool, Never>
let saveCompleted: AnyPublisher<Void, Never>
let imagesFetched: AnyPublisher<[Data], Never>
let imagesFetched: AnyPublisher<[ImageItem], Never>
let presentImageDeleteAlert: AnyPublisher<Void, Never>
let placeholderState: AnyPublisher<(isPlaceholder: Bool, text: String), Never>
}
Expand All @@ -91,7 +91,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {
let pushVCSubject = PassthroughSubject<ClimbRecord, Never>()
let errorMesssageSubject = PassthroughSubject<(String, String), Never>()
let presentPhotoActionSheetSubject = PassthroughSubject<Bool, Never>()
let imagesFetchedSubject = PassthroughSubject<[Data], Never>()
let imagesFetchedSubject = PassthroughSubject<[ImageItem], Never>()
let presentImageDeleteAlertSubject = PassthroughSubject<Void, Never>()
let isPlaceholderSubject = PassthroughSubject<Bool, Never>()
let commentTextSubject = PassthroughSubject<String, Never>()
Expand Down Expand Up @@ -203,7 +203,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {

// Add 화면이면 pendingImages 반환
if isFromAddRecord {
imagesFetchedSubject.send(pendingImages)
imagesFetchedSubject.send(pendingImages.map { ImageItem(data: $0 )})
return
}

Expand All @@ -224,7 +224,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {
return nil
}
}
imagesFetchedSubject.send(imageDatas)
imagesFetchedSubject.send(imageDatas.map { ImageItem(data: $0 )})
}
.store(in: &self.cancellables)
}
Expand Down Expand Up @@ -264,7 +264,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {
.sink { [weak self] imageData in
guard let self else { return }
pendingImages.append(imageData)
imagesFetchedSubject.send(pendingImages)
imagesFetchedSubject.send(pendingImages.map { ImageItem(data: $0 )})
}
.store(in: &cancellables)

Expand Down Expand Up @@ -319,7 +319,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {
.eraseToAnyPublisher()
}
.sink { imageDatas in
imagesFetchedSubject.send(imageDatas)
imagesFetchedSubject.send(imageDatas.map { ImageItem(data: $0 )})
}
.store(in: &cancellables)

Expand Down Expand Up @@ -366,7 +366,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {
index < pendingImages.count {
pendingImages.remove(at: index)
}
imagesFetchedSubject.send(pendingImages)
imagesFetchedSubject.send(pendingImages.map { ImageItem(data: $0 )})
}
.store(in: &cancellables)

Expand Down Expand Up @@ -414,7 +414,7 @@ final class ClimbRecordDetailViewModel: BaseViewModel {
.eraseToAnyPublisher()
}
.sink { imageDatas in
imagesFetchedSubject.send(imageDatas)
imagesFetchedSubject.send(imageDatas.map { ImageItem(data: $0 )})
}
.store(in: &cancellables)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ final class ClimbRecordCollectionViewCell: BaseCollectionViewCell {
}

// 데이터 정보 표기
final func setData(_ data: ClimbRecord, isFirstVisit: Bool, imageDatas: [Data] = []) {
final func setData(_ data: ClimbRecord, isFirstVisit: Bool, imageDatas: [ImageItem] = []) {
let name = data.mountain.name

mountainImageView.image = getMountainImage(date: data.climbDate)
Expand Down Expand Up @@ -129,7 +129,7 @@ final class ClimbRecordCollectionViewCell: BaseCollectionViewCell {
// 로딩 중: placeholder
imageCollectionView.isHidden = false
commentLabel.isHidden = true
applySnapshot(images: [Data()]) // 빈 Data로 indicator 표시
applySnapshot(images: [ImageItem(data: Data())]) // 빈 Data로 indicator 표시
} else {
// 이미지 있음
imageCollectionView.isHidden = false
Expand Down Expand Up @@ -315,23 +315,23 @@ extension ClimbRecordCollectionViewCell {
return UICollectionViewCompositionalLayout(section: section)
}

private func createRegistration() -> UICollectionView.CellRegistration<RatioImageCollectionViewCell, Data> {
return UICollectionView.CellRegistration<RatioImageCollectionViewCell, Data> { cell, indexPath, item in
cell.setImage(imageData: item)
private func createRegistration() -> UICollectionView.CellRegistration<RatioImageCollectionViewCell, ImageItem> {
return UICollectionView.CellRegistration<RatioImageCollectionViewCell, ImageItem> { cell, indexPath, item in
cell.setImage(imageData: item.data)
}
}

private func createDataSource() -> UICollectionViewDiffableDataSource<Section, Data> {
private func createDataSource() -> UICollectionViewDiffableDataSource<Section, ImageItem> {
let registration = createRegistration()
return UICollectionViewDiffableDataSource<Section, Data>(collectionView: imageCollectionView) { collectionView, indexPath, item in
return UICollectionViewDiffableDataSource<Section, ImageItem>(collectionView: imageCollectionView) { collectionView, indexPath, item in
collectionView.dequeueConfiguredReusableCell(using: registration, for: indexPath, item: item)
}
}

private func applySnapshot(images: [Data]) {
var snapshot = NSDiffableDataSourceSnapshot<Section, Data>()
private func applySnapshot(images: [ImageItem]) {
var snapshot = NSDiffableDataSourceSnapshot<Section, ImageItem>()
snapshot.appendSections(Section.allCases)
snapshot.appendItems(images)
snapshot.appendItems(images.uniq(by: \.self))
dataSource.apply(snapshot, animatingDifferences: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ extension ClimbRecordListViewController: UICollectionViewDelegate, UICollectionV
.min { $0.climbDate < $1.climbDate }
let isFirstVisit = firstRecordOfMountain?.id == climbRecord.id

let imageDatas = viewModel.recordImageDatas[climbRecord.id] ?? []
let imageDatas = viewModel.recordImageDatas[climbRecord.id]?.map { ImageItem(data: $0) } ?? []

cell.setImages(row: indexPath.item, total: viewModel.climbRecordList.count)
cell.setData(climbRecord, isFirstVisit: isFirstVisit, imageDatas: imageDatas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ extension MapViewController: UICollectionViewDelegate {
private func applySnapshot(mountains: [MountainDistance]) {
var snapshot = NSDiffableDataSourceSnapshot<Section, MountainDistance>()
snapshot.appendSections(Section.allCases)
snapshot.appendItems(mountains)
snapshot.appendItems(mountains.uniq(by: \.self))
dataSource.apply(snapshot, animatingDifferences: true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ extension MeasureViewController: UITableViewDelegate {
private func applySnapshot(mountains: [MountainInfo]) {
var snapshot = NSDiffableDataSourceSnapshot<Section, MountainInfo>()
snapshot.appendSections([.main])
snapshot.appendItems(mountains)
snapshot.appendItems(mountains.uniq(by: \.id))
dataSource.apply(snapshot, animatingDifferences: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit
import Domain
import SnapKit
import Kingfisher

Expand All @@ -19,8 +20,8 @@ final class ImageCollectionViewCell: BaseCollectionViewCell {
return imageView
}()

func setImage(imageData: Data) {
if let image = UIImage(data: imageData) {
func setImage(imageData: ImageItem) {
if let image = UIImage(data: imageData.data) {
imageView.image = image
} else {
imageView.image = nil
Expand Down
13 changes: 13 additions & 0 deletions Presentation/Sources/Utils/Extensions/Array+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Array+Extension.swift
// Presentation
//
// Created by 김영훈 on 1/31/26.
//

extension Array {
func uniq<T: Hashable>(by keyPath: KeyPath<Element, T>) -> [Element] {
var set = Set<T>()
return filter { set.insert($0[keyPath: keyPath]).inserted }
}
}
6 changes: 4 additions & 2 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ProjectDescription

let iOSVersion = "16.0"
let teamID = "4QUWH828P3"
let appVersion = "1.4.3"
let appVersion = "1.5.0"
let buildNumber = "1"

let project = Project(
Expand Down Expand Up @@ -56,7 +56,8 @@ let project = Project(
"$(TARGET_BUILD_DIR)/$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/GoogleService-Info.plist",
"$(TARGET_BUILD_DIR)/$(EXECUTABLE_PATH)",
"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${PRODUCT_NAME}.debug.dylib"
]
],
basedOnDependencyAnalysis: false
)
],
dependencies: [
Expand All @@ -73,6 +74,7 @@ let project = Project(
"DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym",
"CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION": "YES",
"OTHER_LDFLAGS": "$(inherited) -ObjC",
"ENABLE_DEBUG_DYLIB": "NO",
"DEVELOPMENT_TEAM": .string(teamID),
"MARKETING_VERSION": .string(appVersion),
"CURRENT_PROJECT_VERSION": .string(buildNumber)
Expand Down
File renamed without changes.