I have an app where I need to store a list of products to core data. I call the following method:
var productsList: [ProducttCD] = [] // ProductCd is the codable class used to decode products
private func getSavedProducts() {
let context = appDelegate.persistentContainer.viewContext
let request: NSFetchRequest<ProductCD> = ProductCD.fetchRequest()
do {
productsList = try context.fetch(request)
} catch {
print("Error fetching data from context \(error)")
}
if produtsList.count == 0 {
self.saveProductsToCD(taskType: .saveAll)
} else if let lastSaved = productsLastSaved, lastSaved < (Date().timeIntervalSince1970 - 86400) {
self.saveProductsToCD(taskType: .update)
}
}
Now, what I want to do is to essentially update this DB if it is more that 24 hours old. This means if one attribute for a specific entity has changed, for example, it should update the core data database.
What I had planned to do was to delete then entire database which seems extreme.
I did try to loop through the ids linked to the object, filter those which matched the core data entries and find a match. Bit this tool takes huge amount of time to use. What I would like to do is to delete the entire database of these entries completely. Then I could re save the airports to the blank DB. However, I am not sure how to delete all instances of a spcific property...