I'm trying to first call one function that saves data from firebase to Coredata, and when it's done executing call another function that takes that data from coredata and uses it. I'm using a dispatchGroup and this is my code:
let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
DispatchQueue.main.async {
self.storeStatsDataFromFirebaseToCoreData()
dispatchGroup.leave()
}
dispatchGroup.notify(queue: .main) {
self.storePRData()
}
Now the dispatchGroup works fine. The "storeStatsDateFromFireBaseToCoreData" is being called first, and then the "storePRData". But It seems that the items hasn't finished loading into coredata, so when the "storePRData" func is trying to fetch the items it can't.
Do you guys have any clue to what im missing here? Im a beginner in coding and im thankful for any help.
Greetings, Pontus