Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created February 5, 2023 21:26
Show Gist options
  • Select an option

  • Save foxicode/2a45bff50c087225b9175c942b2e1f67 to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/2a45bff50c087225b9175c942b2e1f67 to your computer and use it in GitHub Desktop.
Contact List
import SnapKit
import UIKit
class ViewControllerLayout: Layout {
lazy var contactList: UITableView = {
let tableView = UITableView()
tableView.showsHorizontalScrollIndicator = false
tableView.showsVerticalScrollIndicator = false
tableView.register(ContactCell.self, forCellReuseIdentifier: ContactCell.cellId)
return tableView
}()
required init() {
super.init()
addSubview(contactList) {
$0.fillHorizontally()
$0.top.equalTo(layoutMarginsGuide.snp.top)
$0.bottom.equalTo(layoutMarginsGuide.snp.bottom).priority(.low)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ViewController: ViewControllerWithLayout<ViewControllerLayout> {
lazy var adapter = ContactsAdapter()
override func viewDidLoad() {
super.viewDidLoad()
adapter.contacts = [
Contact(id: 1, name: "Hamlet", email: "[email protected]"),
Contact(id: 2, name: "Claudius", email: "[email protected]"),
Contact(id: 3, name: "Gertrude", email: "[email protected]"),
Contact(id: 4, name: "Polonius", email: "[email protected]"),
Contact(id: 5, name: "Horatio", email: "[email protected]"),
Contact(id: 6, name: "Ophelia", email: "[email protected]"),
Contact(id: 7, name: "Laertes", email: "[email protected]"),
Contact(id: 8, name: "Fortinbras", email: "[email protected]"),
Contact(id: 9, name: "The Ghost", email: "[email protected]"),
Contact(id: 10, name: "Rosencrantz and Guildenstern", email: "[email protected]"),
Contact(id: 11, name: "Osric", email: "[email protected]"),
Contact(id: 12, name: "Voltimand and Cornelius", email: "[email protected]"),
Contact(id: 13, name: "Marcellus and Bernardo", email: "[email protected]"),
Contact(id: 14, name: "Francisco", email: "[email protected]"),
Contact(id: 15, name: "Reynaldo", email: "[email protected]")
]
layout.contactList.delegate = adapter
layout.contactList.dataSource = adapter
layout.contactList.reloadData()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment