Widget Extension Fixes: - Create standalone WidgetDataProvider for widget data isolation - Add WIDGET_EXTENSION compiler flag for conditional compilation - Fix DataController references in widget-shared files - Sync widget version numbers with main app (23, 1.0.2) - Add WidgetBackground color to asset catalog Warning Resolutions: - Fix UIScreen.main deprecation in BGView and SharingListView - Fix Text '+' concatenation deprecation in PurchaseButtonView and SettingsTabView - Fix exhaustive switch in BiometricAuthManager (add .none case) - Fix var to let in ExportService (3 instances) - Fix unused result warning in NoteEditorView - Fix ForEach duplicate ID warnings in MonthView and YearView Code Quality Improvements: - Wrap bypassSubscription in #if DEBUG for security - Rename StupidAssCustomWidgetObservableObject to CustomWidgetStateViewModel - Add @MainActor to IconViewModel - Replace fatalError with graceful fallback in SharedModelContainer - Add [weak self] to closures in DayViewViewModel - Add OSLog-based AppLogger for production logging - Add ImageCache with NSCache for memory efficiency - Add AccessibilityHelpers with Reduce Motion support - Create DataControllerProtocol for dependency injection - Update .gitignore with secrets exclusions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
//
|
|
// DataControllerDELETE.swift
|
|
// Feels
|
|
//
|
|
// SwiftData DELETE operations.
|
|
//
|
|
|
|
import SwiftData
|
|
import Foundation
|
|
import os.log
|
|
|
|
extension DataController {
|
|
func clearDB() {
|
|
do {
|
|
try modelContext.delete(model: MoodEntryModel.self)
|
|
saveAndRunDataListeners()
|
|
} catch {
|
|
AppLogger.general.error("Failed to clear database: \(error.localizedDescription)")
|
|
}
|
|
}
|
|
|
|
func deleteLast(numberOfEntries: Int) {
|
|
guard let startDate = Calendar.current.date(byAdding: .day, value: -numberOfEntries, to: Date()) else { return }
|
|
let entries = getData(startDate: startDate, endDate: Date(), includedDays: [])
|
|
|
|
for entry in entries {
|
|
modelContext.delete(entry)
|
|
}
|
|
save()
|
|
}
|
|
|
|
func deleteRandomFromLast(numberOfEntries: Int) {
|
|
guard let startDate = Calendar.current.date(byAdding: .day, value: -numberOfEntries, to: Date()) else { return }
|
|
let entries = getData(startDate: startDate, endDate: Date(), includedDays: [])
|
|
|
|
for entry in entries where Bool.random() {
|
|
modelContext.delete(entry)
|
|
}
|
|
save()
|
|
}
|
|
}
|