December 2018
Intermediate to advanced
414 pages
10h 19m
English
Let's begin the refactoring of our view controller, as follows:
protocol ComposeViewControllerDelegate: AnyObject { func composeViewController(_ controller: ComposeViewController, attemptToSend message: String)}class ComposeViewController: UIViewController { enum State { case `default` case error(Error) case sending } private var textView = UITextView() private var sendButton = UIButton() weak var delegate: ComposeViewControllerDelegate? var state: State = .default { didSet { /* todo handle state */ } } func sendTapped(sender: UIButton) { delegate?.composeViewController(self, attemptToSend: textView.text) }}
The view controller is now completely focused on managing views. It is easier to extend and to manage. If we have ...
Read now
Unlock full access