Skip to content

Instantly share code, notes, and snippets.

@johnlahboo
Created September 27, 2016 11:58
Show Gist options
  • Save johnlahboo/075380de0e60dc78f3039a91ebfe9b0a to your computer and use it in GitHub Desktop.
Save johnlahboo/075380de0e60dc78f3039a91ebfe9b0a to your computer and use it in GitHub Desktop.
class ViewModel {
var numberVariable = Variable<String?>(nil)
var isEvenObservable: Observable<String>!
init () {
isEvenObservable = numberVariable.asObservable()
.map {number in
guard let numberTemp = number else {return "Invalid"}
guard let numberIsNumber = Int(numberTemp) else {return (numberTemp + " is not number")}
return (numberIsNumber % 2 == 0) ? numberTemp + " is Even" : numberTemp + " is Odd"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment