Primera build enviada

This commit is contained in:
2026-01-19 14:40:43 +01:00
parent c6be398e5a
commit b03d35194f
36 changed files with 1641 additions and 561 deletions
@@ -2,6 +2,7 @@ import Foundation
import CoreData
import Combine
@MainActor
class SnapshotRepository: ObservableObject {
private let context: NSManagedObjectContext
private let cache = NSCache<NSString, NSArray>()
@@ -9,6 +10,8 @@ class SnapshotRepository: ObservableObject {
@Published private(set) var snapshots: [Snapshot] = []
private var cancellables = Set<AnyCancellable>()
// MARK: - Performance: Shared DateFormatter
private static let monthYearFormatter: DateFormatter = {
let formatter = DateFormatter()
@@ -301,16 +304,17 @@ class SnapshotRepository: ObservableObject {
cacheVersion &+= 1
}
private func setupNotificationObserver() {
NotificationCenter.default.addObserver(
self,
selector: #selector(contextDidChange),
name: .NSManagedObjectContextObjectsDidChange,
object: context
)
/// Clear cache on memory pressure - call from AppDelegate's didReceiveMemoryWarning
func clearCacheOnMemoryPressure() {
cache.removeAllObjects()
}
@objc private func contextDidChange(_ notification: Notification) {
invalidateCache()
private func setupNotificationObserver() {
NotificationCenter.default.publisher(for: .NSManagedObjectContextObjectsDidChange, object: context)
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
self?.invalidateCache()
}
.store(in: &cancellables)
}
}