如何在
之间添加更多单词if(inputText!.text == "motorka"){
我想添加“Motorka”和“MOTORKA”。但以下不起作用:
if(inputText!.text == "motorka", "Motorka", "MOTORKA"){
如何查看超过一个字符串?
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
let touchLocation = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(touchLocation)
if(touchedNode.name == "checkbutton"){
if(inputText!.text == "motorka"){
runAction(SKAction.playSoundFileNamed("correct.wav", waitForCompletion: false))
correct.hidden = false
inputText!.hidden = true
check.hidden = true
let nextLevel = level2(size: size)
nextLevel.scaleMode = scaleMode
let transitionType = SKTransition.crossFadeWithDuration(1.4)
let wait = SKAction.waitForDuration(0.9)
let action = SKAction.runBlock {
view?.presentScene(nextLevel, transition: transitionType)
}
self.runAction(SKAction.sequence([wait, action]))
}
}
答案 0 :(得分:2)
您是否在寻找布尔值OR ||
:
if(inputText!.text == "motorka" || inputText!.text == "Motorka" || inputText!.text == "MOTORKA") { ... }
但是为了使它看起来更好并且在某些情况下更高效,你应该为文本创建一个临时变量,然后对该变量运行检查:
let text = inputText!.text
if(text == "motorka" || text == "Motorka" || text == "MOTORKA") { ... }
您甚至可能想要同时删除OR,并使用lowercaseString
个属性,它将匹配单词"motorka"
的每个大/小写变体:
let text = inputText!.text.lowercaseString
if(text == "motorka") { ... }
答案 1 :(得分:0)
使用NSArray
和containsObject
:
let text = inputText!.text
let wordList = ["motorka", "Motorka", "MOTORKA"] as NSArray
if wordList.containsObject(text) {
...
}