Skip to content

Instantly share code, notes, and snippets.

@arto-heino
Created November 14, 2016 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arto-heino/7ece185c6fbfe0e9b6cd9744978cfbc3 to your computer and use it in GitHub Desktop.
Save arto-heino/7ece185c6fbfe0e9b6cd9744978cfbc3 to your computer and use it in GitHub Desktop.
class PodcastTableViewController: UITableViewController, DataParserObserver {
var podcasts = [Podcast]()
override func viewDidLoad() {
super.viewDidLoad()
self.podcasts = [Podcast]()
let dataParser = HttpRequesting()
dataParser.httpGetPodCasts(parserObserver: self)
}
func podcastsParsed(podcasts: [Podcast]) {
self.podcasts = podcasts
DispatchQueue.main.async {
self.tableView.reloadData()
return
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.podcasts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "PodcastCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! PodcastTableViewCell
cell.collectionLabel.text = self.podcasts[indexPath.row].collection
cell.descriptionLabel.text = self.podcasts[indexPath.row].description
cell.durationLabel.text = self.podcasts[indexPath.row].duration
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment