Skip to content

Instantly share code, notes, and snippets.

@Kdan
Created July 9, 2020 22:33
Show Gist options
  • Save Kdan/ff9f919b217f09c8ce99e6bc6ff534f1 to your computer and use it in GitHub Desktop.
Save Kdan/ff9f919b217f09c8ce99e6bc6ff534f1 to your computer and use it in GitHub Desktop.
protocol Presenter {
/// Present the given content to the user.
func present(title: String, description: String)
}
class ContentHandler {
/// The presenter used to present content.
private let presenter: Presenter
init(presenter: Presenter) {
self.presenter = presenter
}
/// Handles the input and present the corresponding content to the user.
func handleInput(_ input: Int) {
let title: String
let description: String
switch input {
case Int.min...0:
title = "Negative"
description = "Less than zero"
case 0...10:
title = "Positive"
description = "Great input"
default:
title = "Too high"
description = "...Way too high"
}
presenter.present(title: title, description: description)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment