Skip to content
Merged
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
3 changes: 1 addition & 2 deletions DevLog/Presentation/ViewModel/TodoEditorViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ final class TodoEditorViewModel: Store {
var hasDueDate: Bool { dueDate != nil }
var tabViewTag: Tag = .editor
var isValidToSave: Bool {
!title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty &&
!content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
!title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

현재 로직은 문제 없이 동작하지만, 공백을 제외한 문자열이 비어있는지 확인하는 로직은 다른 곳에서도 사용될 가능성이 높습니다. 코드의 가독성을 높이고 재사용성을 확보하기 위해 String에 대한 확장을 추가하는 것을 고려해보시는 건 어떨까요?

예를 들어, 다음과 같은 isBlank 프로퍼티를 추가할 수 있습니다.

extension String {
    var isBlank: Bool {
        self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
    }
}

이 확장을 사용하면 isValidToSave를 아래와 같이 더 명확하고 간결하게 표현할 수 있습니다.

var isValidToSave: Bool {
    !title.isBlank
}

이러한 유틸리티 성격의 확장은 별도 파일로 관리하여 프로젝트 전반에서 활용하는 것이 좋습니다.

}
}

Expand Down
Loading