Base fixes and test harness

This commit is contained in:
alexandrev-tibco
2026-02-01 11:12:57 +01:00
parent f5b13ec924
commit e328767c4a
39 changed files with 3575 additions and 142 deletions
@@ -28,6 +28,14 @@ public class InvestmentSource: NSManagedObject, Identifiable {
customFrequencyMonths = 1
name = ""
}
public override func awakeFromFetch() {
super.awakeFromFetch()
// Defensive: ensure id exists for legacy rows where id may be nil.
if value(forKey: "id") == nil {
setValue(UUID(), forKey: "id")
}
}
}
// MARK: - Notification Frequency
@@ -21,11 +21,35 @@ public class Snapshot: NSManagedObject, Identifiable {
date = Date()
createdAt = Date()
}
public override func awakeFromFetch() {
super.awakeFromFetch()
// Defensive: ensure id exists for legacy rows where id may be nil.
if value(forKey: "id") == nil {
setValue(UUID(), forKey: "id")
}
}
}
// MARK: - Computed Properties
extension Snapshot {
var safeId: UUID {
if let existing = primitiveValue(forKey: "id") as? UUID {
return existing
}
let newId = UUID()
setPrimitiveValue(newId, forKey: "id")
return newId
}
var safeDate: Date {
if let dateValue = primitiveValue(forKey: "date") as? Date {
return dateValue
}
return Date()
}
var decimalValue: Decimal {
value?.decimalValue ?? Decimal.zero
}