我想在xcode上创建一个莫尔斯代码翻译应用程序。英语到莫尔斯的翻译工作正常,但这种逆向过程没有。我的代码有什么问题?
let input = inputTextField.text!
var output = ""
var Dict = [".-" : "a", "-..." : "b"]
for character in input.characters {
let characters = "\(character)"
if let translatedcharacters = Dict[characters] {
output += translatedcharacters
} else {
output += characters
}
}
outputLabel.text = output
显示的输出不是" a"或" b"但只是输入是" .-"或" -..."