Created
September 27, 2016 11:58
-
-
Save johnlahboo/075380de0e60dc78f3039a91ebfe9b0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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