@@ -17,72 +17,76 @@ final class HomeView: UIView {
1717 private let restaurantCellIdentifier = " RestaurantCellIdentifier "
1818
1919 private var restaurants : [ Restaurant ] = [ ]
20+
21+ private lazy var addressView : AddressView = {
22+ let addressView = AddressView ( )
23+ addressView. updateView ( with: . init( address: " R. Guiratinga, 500 " ) )
24+ addressView. translatesAutoresizingMaskIntoConstraints = false
25+ return addressView
26+ } ( )
2027
2128 private lazy var tableView : UITableView = {
22-
2329 let tableView = UITableView ( frame: . zero)
2430 tableView. translatesAutoresizingMaskIntoConstraints = false
25- tableView. register ( UITableViewCell . self, forCellReuseIdentifier: self . restaurantCellIdentifier)
31+ tableView. register ( UITableViewCell . self, forCellReuseIdentifier: restaurantCellIdentifier)
2632 tableView. dataSource = self
2733 return tableView
2834 } ( )
2935
30- init ( ) {
31-
32- super. init ( frame: . zero)
33-
34- self . setupViews ( )
35- }
36-
37- required init ? ( coder: NSCoder ) {
38- fatalError ( " init(coder:) has not been implemented " )
36+ convenience init ( ) {
37+ self . init ( frame: . zero)
38+ setup ( )
3939 }
4040
4141 func updateView( with restaurants: [ Restaurant ] ) {
42-
4342 self . restaurants = restaurants
44- self . tableView. reloadData ( )
43+ tableView. reloadData ( )
4544 }
4645}
4746
48- private extension HomeView {
49-
50- func setupViews( ) {
51-
52- self . backgroundColor = . white
53-
54- self . configureSubviews ( )
55- self . configureSubviewsConstraints ( )
47+ extension HomeView : ViewCode {
48+ func setupSubviews( ) {
49+ addSubview ( addressView)
50+ addSubview ( tableView)
5651 }
57-
58- func configureSubviews ( ) {
59-
60- self . addSubview ( self . tableView )
52+
53+ func setupConstraints ( ) {
54+ setupTableViewConstraints ( )
55+ setupAddressViewConstraints ( )
6156 }
62-
63- func configureSubviewsConstraints( ) {
64-
57+
58+ func setupExtraConfiguration( ) {
59+ backgroundColor = . white
60+ }
61+
62+ private func setupTableViewConstraints( ) {
6563 NSLayoutConstraint . activate ( [
66-
67- self . tableView. leadingAnchor. constraint ( equalTo: self . safeAreaLayoutGuide. leadingAnchor) ,
68- self . tableView. trailingAnchor. constraint ( equalTo: self . safeAreaLayoutGuide. trailingAnchor) ,
69- self . tableView. topAnchor. constraint ( equalTo: self . safeAreaLayoutGuide. topAnchor) ,
70- self . tableView. bottomAnchor. constraint ( equalTo: self . safeAreaLayoutGuide. bottomAnchor)
64+ tableView. leadingAnchor. constraint ( equalTo: safeAreaLayoutGuide. leadingAnchor) ,
65+ tableView. trailingAnchor. constraint ( equalTo: safeAreaLayoutGuide. trailingAnchor) ,
66+ tableView. topAnchor. constraint ( equalTo: addressView. bottomAnchor) ,
67+ tableView. bottomAnchor. constraint ( equalTo: safeAreaLayoutGuide. bottomAnchor)
68+ ] )
69+ }
70+
71+ private func setupAddressViewConstraints( ) {
72+ NSLayoutConstraint . activate ( [
73+ addressView. leadingAnchor. constraint ( equalTo: safeAreaLayoutGuide. leadingAnchor) ,
74+ addressView. trailingAnchor. constraint ( equalTo: safeAreaLayoutGuide. trailingAnchor) ,
75+ addressView. topAnchor. constraint ( equalTo: safeAreaLayoutGuide. topAnchor)
7176 ] )
7277 }
7378}
7479
7580extension HomeView : UITableViewDataSource {
7681
7782 public func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
78-
79- return self . restaurants. count
83+ return restaurants. count
8084 }
8185
8286 public func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
8387
84- let cell = tableView. dequeueReusableCell ( withIdentifier: self . restaurantCellIdentifier) !
85- cell. textLabel? . text = self . restaurants [ indexPath. row] . name
88+ let cell = tableView. dequeueReusableCell ( withIdentifier: restaurantCellIdentifier) !
89+ cell. textLabel? . text = restaurants [ indexPath. row] . name
8690 return cell
8791 }
8892}
0 commit comments