How to recursively fetch data via Alamofire for a tree like structure?

Viewed 175

I'm using Alamofire for API requests within my app. A usecase requires that I recursively fetch genealogy data for a family tree such that the initial api call retrieves data for the singular parent (oldest member of the family). The data returned will contain arrays of the next generation of people in the family tree as well as the generation after that & looks like so i.e. parent - [sons] - [grandsons]. I now need to fetch the data for each of the sons & grandsons, so on & so forth, with the data always being nested 2 levels deep until the family tree is exhausted. I'm stuck thinking of ways to implement such a recursive API fetch using Alamofire :( How can I achieve something like this? Any help is welcome.

EDIT: How do I recursively fetch data for a family tree where the response data for each person returns array of people (per generation) of the next two generations?

1 Answers

Hi i am not going to solve your problem but have an idea to follow this

first of all refer the trie data structure https://www.raywenderlich.com/892-swift-algorithm-club-swift-trie-data-structure

Step 1: Create your simple method for request and response of alamofire for ex. callAPI()

Step 2: in above link there is add method where you call a method of callAPI() and add response array one by one using add.

this is just an approch. you may find a simpler way.

There is once contain method also which helps you to find your subtree data.

Related