Skip to content

Instantly share code, notes, and snippets.

@gegagome
Last active August 29, 2015 14:16
Show Gist options
  • Save gegagome/d0b695dd921fee08dc7c to your computer and use it in GitHub Desktop.
Save gegagome/d0b695dd921fee08dc7c to your computer and use it in GitHub Desktop.
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