Skip to content

Instantly share code, notes, and snippets.

@Bilguun132
Last active February 22, 2019 03:27
Show Gist options
  • Save Bilguun132/ee25cc6b03eabef4106478e6b7fb2516 to your computer and use it in GitHub Desktop.
Save Bilguun132/ee25cc6b03eabef4106478e6b7fb2516 to your computer and use it in GitHub Desktop.
TableView-Tutorial-UserDataSourceProvider
import Foundation
import UIKit
public class UserDataSourceProvider: NSObject, UITableViewDelegate, UITableViewDataSource {
//private var to hold the user manager
private let userManager: UserManager
//initialize the user manager
init(userManager: UserManager) {
self.userManager = userManager
}
//tableview delegates declared here
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userManager.userCount
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! UserTableViewCell
cell.configure(user: userManager.getUser(at: indexPath.row))
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment