2 years ago

#15714

test-img

Pontus

How to fetch newly written objects in coredata

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

swift

xcode

core-data

dispatch-queue

dispatchgroup

0 Answers

Your Answer

Accepted video resources