I am using Swift. I have the following fetchData() method in my view model:
func fetchData() {
donorsRepository.fetchData()
donor = donorsRepository.donor
}
As you can see, inside the method body, another fetchData() method is called on my repository. The donor property on my view model should then be assigned to the repository's donor property. the problem is that this needs to happen after the repository's fetchData() method has completed. So I need to capture the line "donor = repository.donor" inside a closure. How do I do that?
I tried writing the closure like this:
func fetchData() {
donorsRepository.fetchData() { donor in
self.donor = donorsRepository.donor }
}
But it gave me an error in the first line of the method body, saying "Extra trailing closure passed in call".