Last active
August 29, 2015 14:16
-
-
Save gegagome/d0b695dd921fee08dc7c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import UIKit | |
| class Bob { | |
| class func hey(prompt: String) -> String { | |
| let shouting = "Woah, chill out!" | |
| let question = "Sure." | |
| let touchy = "Fine, be that way." | |
| let apathy = "Whatever." | |
| if loopForMatch(type: NSCharacterSet.uppercaseLetterCharacterSet(), stringToEvaluate: prompt) { | |
| return shouting | |
| } | |
| else if loopForMatch(type: NSCharacterSet.whitespaceCharacterSet(), stringToEvaluate: prompt) || prompt.isEmpty { | |
| return touchy | |
| } | |
| else if (prompt.hasSuffix("?")){ | |
| return question | |
| } | |
| else { | |
| return apathy | |
| } | |
| } | |
| class func loopForMatch (#type: NSCharacterSet, stringToEvaluate: String) -> Bool { | |
| var isUpper: Bool = false | |
| for chrs in stringToEvaluate { | |
| if !isMatch(type: type, characterToEvaluate: String(chrs)) { | |
| isUpper = false | |
| break | |
| } | |
| else { | |
| isUpper = true | |
| } | |
| } | |
| return isUpper | |
| } | |
| class func isMatch(#type: NSCharacterSet, characterToEvaluate: String) -> Bool { | |
| return characterToEvaluate.rangeOfCharacterFromSet(type) != nil | |
| } | |
| } | |
| //Bob.hey("hello") | |
| //Bob.hey("Tom-ay-to, tom-aaaah-to") | |
| Bob.hey("WATCH OUT!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment