This is a very broad question and is generally not suitable for StackOverflow, which is for more "granular questions".
That said, I would recommend creating a class called DataManager
or something like that. In terms of making your API calls, I would recommend using something like Alamofire
for making API calls. Lastly, I would recommend reading up on the Codable
protocol for decoding the JSON the API sends back. When you decode your JSON, you'll want to store the structs somewhere where your view controller can see it.
To use CocoaPods, here's a good primer (You'd use them for Alamofire).
Your data manager would look something like this (I'll use NSObject
for simplicity's sake, but you could just create your own class):
struct Shows: Codable {
// Whatever the API sends back, you've got to map it here
}
class DataManager: NSObject {
var shows: [Shows] = [] // empty array of shows to start
func methodToGetAPIResponse() {
// Alamofire call & JSON decoding here
// Once you get a valid response, shows = try JSONDecoder().decode...
}
}
You could so something like this for your DataManager
in your view controller class:
let dataManager = DataManager()
Then, in your UITableViewDataSource methods, numberOfRowsAtIndexPath
would be return dataManager.shows.count
and cellForRowAtIndexPath
you'd get a hold of the object to populate your labels like so:
let show = dataManager.shows[indexPath.row]
Anyway, that ought to be enough to get you started. Good luck! Try to be more granular with your questions in the future.