Seng Wee
Seng Wee

Reputation: 624

Delaying Data Source methods after remote images are downloaded

I'm using this library https://github.com/Yalantis/Koloda Basically this is a pod that helps me implement a Tinder-like swiping interface.

This pod has a Data Source method called kolodaNumberOfCards(_ koloda: KolodaView) which requires you to declare how many cards the program is expecting to show in the Koloda View.

func kolodaNumberOfCards(_ koloda: KolodaView) -> Int {
        return allCards.list.count
}

I am implementing a MVC architecture in my app so I have a Data Model class file which I instantiate at the top of this current view controller.

var allCards = QuestionBank()

In QuestionBank class, I have a list (array) of Card objects which contains all the metadata of the Card objects. Card object also contains the UIImage I want to instantiate in the KolodaCard View.

PROBLEM COMES when I do not have the Card objects in the QuestionBank list array at init! These Card objects are appended to the list after I fetch data remotely from an API.

However, in my ViewController containing the KolodaView, I need to declare how many cards the program is expecting to show in the Koloda View. Since list.count is 0 when you first enter the ViewController, the KolodaView would thus expect 0 card!

Currently my KolodaView is not showing any of my downloaded images.

Is there a way to delay the Data Source methods by Koloda so that the program can wait for all the data to be fetched from API or is there another solution around this problem?

Upvotes: 0

Views: 142

Answers (0)

Related Questions