diff --git a/DevLog/Domain/Entity/PushNotification.swift b/DevLog/Domain/Entity/PushNotification.swift index 06b29eeb..6d2a00bc 100644 --- a/DevLog/Domain/Entity/PushNotification.swift +++ b/DevLog/Domain/Entity/PushNotification.swift @@ -7,7 +7,7 @@ import Foundation -struct PushNotification { +struct PushNotification: Hashable { let id: String let title: String let body: String diff --git a/DevLog/Domain/Entity/SystemTodoCategory.swift b/DevLog/Domain/Entity/SystemTodoCategory.swift index e49fdd52..32020626 100644 --- a/DevLog/Domain/Entity/SystemTodoCategory.swift +++ b/DevLog/Domain/Entity/SystemTodoCategory.swift @@ -7,7 +7,7 @@ import Foundation -enum SystemTodoCategory: String, CaseIterable { +enum SystemTodoCategory: String, CaseIterable, Hashable { case issue // 이슈 case feature // 신규 기능 case improvement // 개선/리팩터링 diff --git a/DevLog/Domain/Entity/Todo.swift b/DevLog/Domain/Entity/Todo.swift index e34da02c..da3c69e9 100644 --- a/DevLog/Domain/Entity/Todo.swift +++ b/DevLog/Domain/Entity/Todo.swift @@ -7,7 +7,7 @@ import Foundation -struct Todo: Equatable { +struct Todo: Hashable { let id: String var isPinned: Bool // 해당 할 일이 상단에 고정되어 있는지 여부 var isCompleted: Bool // 해당 할 일의 완료 여부 diff --git a/DevLog/Domain/Entity/TodoCategory.swift b/DevLog/Domain/Entity/TodoCategory.swift index a914869a..85e177db 100644 --- a/DevLog/Domain/Entity/TodoCategory.swift +++ b/DevLog/Domain/Entity/TodoCategory.swift @@ -7,7 +7,7 @@ import Foundation -enum TodoCategory: Equatable { +enum TodoCategory: Hashable { case system(SystemTodoCategory) case user(UserTodoCategory) diff --git a/DevLog/Domain/Entity/TodoReference.swift b/DevLog/Domain/Entity/TodoReference.swift index 3b8a7470..5a7ccf23 100644 --- a/DevLog/Domain/Entity/TodoReference.swift +++ b/DevLog/Domain/Entity/TodoReference.swift @@ -7,7 +7,7 @@ import Foundation -struct TodoReference { +struct TodoReference: Hashable { let id: String let title: String let category: TodoCategory diff --git a/DevLog/Domain/Entity/UserTodoCategory.swift b/DevLog/Domain/Entity/UserTodoCategory.swift index f35ff6e0..9b05b766 100644 --- a/DevLog/Domain/Entity/UserTodoCategory.swift +++ b/DevLog/Domain/Entity/UserTodoCategory.swift @@ -7,7 +7,7 @@ import Foundation -struct UserTodoCategory: Equatable { +struct UserTodoCategory: Hashable { var id: String var name: String var colorHex: String diff --git a/DevLog/Domain/Entity/WebPage.swift b/DevLog/Domain/Entity/WebPage.swift index fb1b5305..5a16ad80 100644 --- a/DevLog/Domain/Entity/WebPage.swift +++ b/DevLog/Domain/Entity/WebPage.swift @@ -7,7 +7,7 @@ import Foundation -struct WebPage { +struct WebPage: Hashable { let title: String? let url: URL let displayURL: URL diff --git a/DevLog/Presentation/Structure/Profile/ProfileSelectedDayActivity.swift b/DevLog/Presentation/Structure/Profile/ProfileSelectedDayActivity.swift index 9ad52abf..fb56c40e 100644 --- a/DevLog/Presentation/Structure/Profile/ProfileSelectedDayActivity.swift +++ b/DevLog/Presentation/Structure/Profile/ProfileSelectedDayActivity.swift @@ -20,16 +20,4 @@ struct ProfileSelectedDayActivity: Identifiable, Hashable { } return showsCreated ? "생성" : "완료" } - - static func == (lhs: Self, rhs: Self) -> Bool { - lhs.todo.id == rhs.todo.id - && lhs.showsCreated == rhs.showsCreated - && lhs.showsCompleted == rhs.showsCompleted - } - - func hash(into hasher: inout Hasher) { - hasher.combine(todo.id) - hasher.combine(showsCreated) - hasher.combine(showsCompleted) - } } diff --git a/DevLog/Presentation/Structure/PushNotificationItem.swift b/DevLog/Presentation/Structure/PushNotificationItem.swift index cce0d540..dd8273fb 100644 --- a/DevLog/Presentation/Structure/PushNotificationItem.swift +++ b/DevLog/Presentation/Structure/PushNotificationItem.swift @@ -25,12 +25,4 @@ struct PushNotificationItem: Identifiable, Hashable { self.todoId = notification.todoId self.todoCategory = notification.todoCategory } - - static func == (lhs: PushNotificationItem, rhs: PushNotificationItem) -> Bool { - lhs.id == rhs.id - } - - func hash(into hasher: inout Hasher) { - hasher.combine(id) - } } diff --git a/DevLog/Presentation/Structure/RecentTodoItem.swift b/DevLog/Presentation/Structure/RecentTodoItem.swift index 0d972555..57ac2cdc 100644 --- a/DevLog/Presentation/Structure/RecentTodoItem.swift +++ b/DevLog/Presentation/Structure/RecentTodoItem.swift @@ -25,12 +25,4 @@ struct RecentTodoItem: Identifiable, Hashable { self.tags = todo.tags self.category = todo.category } - - static func == (lhs: RecentTodoItem, rhs: RecentTodoItem) -> Bool { - lhs.id == rhs.id - } - - func hash(into hasher: inout Hasher) { - hasher.combine(id) - } } diff --git a/DevLog/Presentation/Structure/TodayTodoItem.swift b/DevLog/Presentation/Structure/TodayTodoItem.swift index 7e583bbc..7afd16cc 100644 --- a/DevLog/Presentation/Structure/TodayTodoItem.swift +++ b/DevLog/Presentation/Structure/TodayTodoItem.swift @@ -27,12 +27,4 @@ struct TodayTodoItem: Identifiable, Hashable { self.dueDate = todo.dueDate self.category = todo.category } - - static func == (lhs: TodayTodoItem, rhs: TodayTodoItem) -> Bool { - lhs.id == rhs.id - } - - func hash(into hasher: inout Hasher) { - hasher.combine(id) - } } diff --git a/DevLog/Presentation/Structure/UserTodoCategoryItem.swift b/DevLog/Presentation/Structure/UserTodoCategoryItem.swift index cabd7b82..cd3ad23b 100644 --- a/DevLog/Presentation/Structure/UserTodoCategoryItem.swift +++ b/DevLog/Presentation/Structure/UserTodoCategoryItem.swift @@ -21,12 +21,4 @@ struct UserTodoCategoryItem: Identifiable, Hashable { var localizedName: String { userTodoCategory.name } var color: Color { Color(hexString: userTodoCategory.colorHex) ?? .gray } - - static func == (lhs: UserTodoCategoryItem, rhs: UserTodoCategoryItem) -> Bool { - lhs.id == rhs.id - } - - func hash(into hasher: inout Hasher) { - hasher.combine(id) - } } diff --git a/DevLog/Presentation/Structure/WebPageItem.swift b/DevLog/Presentation/Structure/WebPageItem.swift index 2133a7bb..bc143168 100644 --- a/DevLog/Presentation/Structure/WebPageItem.swift +++ b/DevLog/Presentation/Structure/WebPageItem.swift @@ -20,13 +20,3 @@ struct WebPageItem: Identifiable, Hashable { var displayURL: String { metadata.displayURL.absoluteString } var imageURL: URL? { metadata.imageURL } } - -extension WebPageItem { - func hash(into hasher: inout Hasher) { - hasher.combine(metadata.url) - } - - static func == (lhs: WebPageItem, rhs: WebPageItem) -> Bool { - lhs.metadata.url == rhs.metadata.url - } -} diff --git a/DevLog/Presentation/ViewModel/TodoManageViewModel.swift b/DevLog/Presentation/ViewModel/TodoManageViewModel.swift index 4feffe8d..eea980c9 100644 --- a/DevLog/Presentation/ViewModel/TodoManageViewModel.swift +++ b/DevLog/Presentation/ViewModel/TodoManageViewModel.swift @@ -53,13 +53,13 @@ final class TodoManageViewModel: Store { var placeholder: String { guard - let categoryItem = state.category, - case .user(let userTodoCategory) = categoryItem.category + let item = state.category, + case .user(let category) = item.category else { return "이름" } - return userTodoCategory.name + return category.name } var categoryNameCountText: String { @@ -81,28 +81,36 @@ final class TodoManageViewModel: Store { return false } - let trimmedCategoryName = category.name.trimmingCharacters(in: .whitespacesAndNewlines) - if trimmedCategoryName.isEmpty { + let name = category.name.trimmingCharacters(in: .whitespacesAndNewlines) + if name.isEmpty { return false } if SystemTodoCategory.allCases.contains(where: { - $0.rawValue.caseInsensitiveCompare(trimmedCategoryName) == .orderedSame + $0.rawValue.caseInsensitiveCompare(name) == .orderedSame }) { return false } if state.preferences.contains(where: { item in - guard case .user(let userTodoCategory) = item.category, - userTodoCategory.id != category.id else { + guard case .user(let userCategory) = item.category, + userCategory.id != category.id else { return false } - return userTodoCategory.name.caseInsensitiveCompare(trimmedCategoryName) == .orderedSame + return userCategory.name.caseInsensitiveCompare(name) == .orderedSame }) { return false } + if let item = state.preferences.first(where: { $0.id == item.id }), + case .user(let originalCategory) = item.category { + let originalName = originalCategory.name.trimmingCharacters(in: .whitespacesAndNewlines) + if originalName == name && originalCategory.colorHex == category.colorHex { + return false + } + } + return true }