Migrate from Core Data to SwiftData
- Replace Core Data with SwiftData for iOS 18+ - Create MoodEntryModel as @Model class replacing MoodEntry entity - Create SharedModelContainer for App Group container sharing - Create DataController with CRUD extensions replacing PersistenceController - Update all views and view models to use MoodEntryModel - Update widget extension to use SwiftData - Remove old Core Data files (Persistence*.swift, .xcdatamodeld) - Add EntryType enum with all entry type cases - Fix widget label truncation with proper spacing and text scaling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,13 +5,13 @@
|
||||
// Created by Trey Tartt on 2/17/22.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
|
||||
/*
|
||||
current day 3/5/22
|
||||
|
||||
|
||||
..... before time | after time .....
|
||||
|
||||
day option = .today
|
||||
@@ -19,24 +19,25 @@ import SwiftUI
|
||||
voting for 3/4 | voting for 3/5
|
||||
------------------------*-------------------------
|
||||
db should contain 3/3 | db should contain 3/4
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
|
||||
day option = .yesterday
|
||||
--------
|
||||
voting for 3/3 | voting for 3/4
|
||||
------------------------*-------------------------
|
||||
db should contain 3/2 | db should contain 3/3
|
||||
|
||||
|
||||
*/
|
||||
@MainActor
|
||||
class ShowBasedOnVoteLogics {
|
||||
static private func returnCurrentVoteStatus(onboardingData: OnboardingData) -> (passedTimeToVote: Bool, inputDay: DayOptions) {
|
||||
let passedTimeToVote = ShowBasedOnVoteLogics.passedTodaysVotingUnlock(voteDate: onboardingData.date)
|
||||
let inputDay: DayOptions = onboardingData.inputDay
|
||||
|
||||
|
||||
return (passedTimeToVote, inputDay)
|
||||
}
|
||||
|
||||
|
||||
static public func passedTodaysVotingUnlock(voteDate: Date) -> Bool {
|
||||
let currentDateComp = Calendar.current.dateComponents([.hour, .minute], from: Date())
|
||||
let savedDateComp = Calendar.current.dateComponents([.hour, .minute], from: voteDate)
|
||||
@@ -45,32 +46,25 @@ class ShowBasedOnVoteLogics {
|
||||
let currentMin = currentDateComp.minute,
|
||||
let savedHour = savedDateComp.hour,
|
||||
let savedMin = savedDateComp.minute {
|
||||
|
||||
|
||||
if currentHour > savedHour {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
if currentHour == savedHour {
|
||||
return currentMin >= savedMin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
static public func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool {
|
||||
|
||||
static public func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool {
|
||||
let startDate = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: onboardingData).startOfDay
|
||||
let endDate = startDate.endOfDay
|
||||
|
||||
let fetchRequest = NSFetchRequest<MoodEntry>(entityName: "MoodEntry")
|
||||
let fromPredicate = NSPredicate(format: "%@ <= %K", startDate
|
||||
as NSDate, #keyPath(MoodEntry.forDate))
|
||||
let toPredicate = NSPredicate(format: "%K < %@", #keyPath(MoodEntry.forDate), endDate as NSDate)
|
||||
let datePredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [fromPredicate, toPredicate])
|
||||
fetchRequest.predicate = datePredicate
|
||||
let entries = try! PersistenceController.shared.viewContext.count(for: fetchRequest)
|
||||
|
||||
return entries < 1
|
||||
let entry = DataController.shared.getEntry(byDate: startDate)
|
||||
return entry == nil || entry?.mood == .missing
|
||||
}
|
||||
|
||||
static public func getCurrentVotingDate(onboardingData: OnboardingData) -> Date {
|
||||
|
||||
Reference in New Issue
Block a user