Skip to content

Instantly share code, notes, and snippets.

@MartinMoizard
Last active August 22, 2017 14:42
Show Gist options
  • Save MartinMoizard/63af25fe5f97c1e8ba40ba195ff6cbe5 to your computer and use it in GitHub Desktop.
Save MartinMoizard/63af25fe5f97c1e8ba40ba195ff6cbe5 to your computer and use it in GitHub Desktop.
final class SayHelloViewModel: ViewModelType {
struct Input {
let name: Observable<String>
let validate: Observable<Void>
}
struct Output {
let greeting: Driver<String>
}
func transform(input: Input) -> Output {
let greeting = input.validate
.withLatestFrom(input.name)
.map { name in
return "Hello \(name)!"
}
.startWith("")
.asDriver(onErrorJustReturn: ":-(")
return Output(greeting: greeting)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment