Skip to content

Instantly share code, notes, and snippets.

@mimthath4
Last active January 29, 2020 04:38
Show Gist options
  • Save mimthath4/7d02ebf63284e1723edb77af329b758a to your computer and use it in GitHub Desktop.
Save mimthath4/7d02ebf63284e1723edb77af329b758a to your computer and use it in GitHub Desktop.
import UIKit
import MINetworkKit
class AlbumsViewController: MITableViewController {
override func registerCells() {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "albumCell")
updateAlbums()
}
}
extension AlbumsViewController: MINetworkable {
func updateAlbums() {
send(TypicodeRequest.getAlbums, returns: [Albums]()) { [weak self] result in
guard let strongSelf = self else { return }
switch result {
case .success(let albums):
let section = SectionItem(id: "Album", header: nil, items: albums)
strongSelf.sections.append(section)
DispatchQueue.main.sync {
strongSelf.tableView.reloadData()
}
case .failure(let error):
print(error)
}
}
}
}
extension Album: RowItem {
func getCell(at indexPath: IndexPath, of tableView: UITableView) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "albumCell", for: indexPath)
cell.textLabel?.text = self.title
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment