I have a scheduled function uses a private queue context to fetch objects from CoreData and uploads them to a server and deletes the fetched objects if successfully uploaded. The upload function is an async function that uses URLSession.
context.perform {
do {
let fetchRequest = NSFetchRequest<CustomEntity>
fetchRequest = CustomEntity.fetchRequest()
let objects = try context.fetch(fetchRequest)
let data = JSONSerialization.data(withJsonObject: objects, options: [])
//
await uploadToServer(data)
// delete after successful upload:
objects.forEach(context.delete)
try context.save()
} catch let error {
}
}
However, this doesn't seem legal though. xcode gives me an error: 'async' call in a function that does not support concurrency
.
Stuck on how to invoke the async function within the context.perform { }
block