- Add default values to all SwiftData attributes (CloudKit requirement) - Make memos relationship optional (CloudKit requirement) - Add allMemos computed property for safe unwrapping - Add remote-notification background mode for CloudKit push sync Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
923 B
Swift
46 lines
923 B
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
@Model
|
|
final class DiaryEntry {
|
|
var date: Date = Date.now
|
|
var summary: String?
|
|
var isSummaryGenerated: Bool = false
|
|
@Relationship(deleteRule: .cascade, inverse: \VoiceMemo.entry)
|
|
var memos: [VoiceMemo]? = []
|
|
var createdAt: Date = Date.now
|
|
var updatedAt: Date = Date.now
|
|
|
|
init(date: Date) {
|
|
self.date = Calendar.current.startOfDay(for: date)
|
|
self.summary = nil
|
|
self.isSummaryGenerated = false
|
|
self.memos = []
|
|
self.createdAt = .now
|
|
self.updatedAt = .now
|
|
}
|
|
|
|
var allMemos: [VoiceMemo] {
|
|
memos ?? []
|
|
}
|
|
|
|
var combinedTranscript: String {
|
|
allMemos
|
|
.sorted { $0.recordedAt < $1.recordedAt }
|
|
.compactMap(\.transcript)
|
|
.joined(separator: "\n\n")
|
|
}
|
|
|
|
var hasMemos: Bool {
|
|
!allMemos.isEmpty
|
|
}
|
|
|
|
var hasTranscripts: Bool {
|
|
allMemos.contains { $0.transcript != nil }
|
|
}
|
|
|
|
var formattedDate: String {
|
|
date.formatted(.dateTime.day().month(.wide).year())
|
|
}
|
|
}
|