Base fixes and test harness
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user