MVCについて

##・Model
Modelでは、データ処理、ビジネスロジック、データの更新をViewControllerへ通知するなどの役割を担う

##・View
Viewでは、表示やユーザーからの入力や出力を行う

##・Controller
Controllerでは、ユーザーからの入力によってModelとViewの仲立ちを行う


<h2>Model</h2>
```swift
struct CountModel {
    var count: Int = 0
}
```



<h2>view</h2>
```swift
final class ThirdTableViewCell: UITableViewCell {

    @IBOutlet private weak var countLabel: UILabel!
    
    override func prepareForReuse() {
        super.prepareForReuse()
        
        countLabel.text = nil
    }
    
    func configure(countModel: Int) {
        countLabel.text = countModel.description
    }
}
```

<h2>Controller</h2>
```swift
import UIKit

final class InitialViewController: UIViewController {
    
    static func makeFromStoryboard() -> InitialViewController {
        let vc = UIStoryboard.initialViewController
        return vc
    }
    
    
    @IBAction private func showSecondButton(_ sender: Any) {
        Router.showSecond(vc: self)
    }
}



```
```swift
import UIKit

final class SecondViewController: UIViewController {
    
    var countModel = CountModel.init(count: 0)
    
    @IBOutlet private weak var countLabel: UILabel! {
        didSet{
            countLabel.text = countModel.count.description
        }
    }
    
    static func makeFromStoryboard() -> SecondViewController {
        let vc = UIStoryboard.secondViewController
        return vc
    }
    
    @IBAction private func countUpButton(_ sender: Any) {
        print("カウントされました")
        countModel.count += 1
        countLabel.text = countModel.count.description
    }
    
    @IBAction private func showThirdButton(_ sender: Any) {
        Router.showThird(vc: self, countModel: countModel)
    }
    
}
```

```swift

import UIKit

final class ThirdViewController: UIViewController {
    
    
    private let CELL_NIB_NAME = "ThirdTableViewCell"
    private let CELL_ID = "ThirdTableViewCell"
    
    var countModel: [CountModel] = []
    
    @IBOutlet private weak var tableView: UITableView! {
        didSet {
            let cellNIB = UINib(nibName: CELL_NIB_NAME, bundle: nil)
            tableView.register(cellNIB, forCellReuseIdentifier: CELL_ID)
            
            tableView.isHidden = true
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
        
        tableView.isHidden = false
    }
    
    static func makeFromStoryboard(countModel: CountModel) -> ThirdViewController {
        let vc = UIStoryboard.thirdViewController
        vc.countModel.append(countModel)
        return vc
    }
    
}

extension ThirdViewController: UITableViewDelegate {
    
}

extension ThirdViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard
            let cell = tableView.dequeueReusableCell(withIdentifier: CELL_ID, for: indexPath) as? ThirdTableViewCell
        else {
            
            return UITableViewCell()
        }
        
    
        let count = countModel[indexPath.row].count
        
        cell.configure(countModel: count)
        
        
        return cell
    }
    
    
}


```

<h2>Extension</h2>
```swift

import UIKit

// Storyboardの読み込みを１箇所にまとめる
extension UIStoryboard {
  static var initialViewController: InitialViewController {
    UIStoryboard.init(name: "Initial", bundle: nil).instantiateInitialViewController() as! InitialViewController
  }

  static var secondViewController: SecondViewController {
    UIStoryboard.init(name: "Second", bundle: nil).instantiateInitialViewController() as! SecondViewController
  }

  static var thirdViewController: ThirdViewController {
    UIStoryboard.init(name: "Third", bundle: nil).instantiateInitialViewController() as! ThirdViewController
  }
}
```