I need to enable my app keep the data for a long time. When I started reading articles on the topic I faced 3 different approaches and realized I do not see any differences. Please explain pros and cons of the following fetch methods:
A)
container.performBackgroundTask { context in
self.data = try! context.fetch(request)
DispatchQueue.main.async {
self.updateUI()
}
}
B)
let context = container.newBackgroundContext()
context.perform {
self.data = try! context.fetch(request)
DispatchQueue.main.async {
self.updateUI()
}
}
C)
let context = container.newBackgroundContext()
let asyncFetchRequest = NSAsynchronousFetchRequest(fetchRequest: request) { result in
self.data = result.finalResult!.first!.data!
DispatchQueue.main.async {
self.updateUI()
}
}
try! context.execute(asyncFetchRequest)