Conversation
Monfi98
reviewed
Jun 10, 2025
Comment on lines
+59
to
+90
| /// 모든 `Quote` → `SharedQuote` 로 변환한 뒤 | ||
| /// App Group(UserDefaults) 에 저장하고 위젯 타임라인을 즉시 갱신. | ||
| /// | ||
| /// 1. 저장소에서 모든 Quote 를 가져옴. | ||
| /// 2. ISBN → 책 제목을 비동기로 조회하여 `SharedQuote` 생성 | ||
| /// 3. `SharedQuotesStore.save(_:)` 호출로 JSON 덤프 | ||
| /// 4. `WidgetCenter.shared.reloadAllTimelines()` 로 위젯 갱신 | ||
| /// | ||
| /// - Throws: | ||
| /// - `RepositoryError.fetchError` : Quote 또는 Book 로드 과정에서 발생 | ||
| /// - `EncodingError` : JSON 인코딩 실패 | ||
| private func syncSharedDefaults() async throws { | ||
| let allQuotes = try await quoteRepository.fetchAllQuotes() | ||
|
|
||
| let sharedQuotes: [SharedQuote] = try await withThrowingTaskGroup(of: SharedQuote.self) { group in | ||
| for quote in allQuotes { | ||
| group.addTask { | ||
| let title = try? await self.loadBookTitle(quote.isbn) | ||
| return SharedQuote( | ||
| id: quote.id, | ||
| content: quote.content, | ||
| bookTitle: title ?? "" // 제목 없으면 빈 문자열 | ||
| ) | ||
| } | ||
| } | ||
| return try await group.reduce(into: []) { $0.append($1) } | ||
| } | ||
|
|
||
| try SharedQuotesStore.save(sharedQuotes) | ||
|
|
||
| // 새로운 데이터가 쓰였으니 위젯 타임라인 즉시 갱신 | ||
| WidgetCenter.shared.reloadAllTimelines() |
Contributor
There was a problem hiding this comment.
질문) 왜 Quote를 안쓰고 SharedQuote를 쓰나요?
Contributor
Author
There was a problem hiding this comment.
앱그룹으로 UserDefaults를 이용해 JSON으로 변경하는 과정이 필요한데 불필요한거 쳐내고 필요한것만 쓰기위해 재가공한것입니다.
Contributor
There was a problem hiding this comment.
p0) 그렇다면 더더욱 필요없을 것 같습니다. AppGroup을 사용하면 앱내에서 같은 GroupContainer를 사용하기 때문에 SwiftData를 그대로 쓸 수 있습니다.
Monfi98
reviewed
Jun 10, 2025
Comment on lines
+35
to
+36
| let entry = randomEntry() | ||
| let nextUpdate = Calendar.current.date(byAdding: .minute, value: 30, to: entry.date)! |
Contributor
There was a problem hiding this comment.
ChatGPT사용할때 꼭 코드에 대해 확인하고 써주세요.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 PR 개요
💡 PR 유형
✏️ 변경 사항 요약
🔗 관련 이슈
🧪 테스트 내역
🎨 스크린샷 또는 시연 영상 (선택)
✅ PR 체크리스트
💬 추가 설명 or 리뷰 포인트 (선택)