【发布时间】:2016-10-11 06:27:36
【问题描述】:
我是编程新手,我正在尝试将这种 if else 结构转换为 Swift 语言的 Switch 案例,感谢您的帮助,谢谢。
这是我的代码
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "ShowDefinition") {
if let destinationViewController = segue.destinationViewController as? EnglishViewController {
if let definition = sender as? String {
if definition == "Abstraction" {
destinationViewController.titleMsg = "Abstraction"
destinationViewController.definitionMsg = "definition 1"
} else if definition == "Binary System" {
destinationViewController.titleMsg = "Binary System"
destinationViewController.definitionMsg = "definition 2"
} else if definition == "Computer" {
destinationViewController.titleMsg = "Computer"
destinationViewController.definitionMsg = "definition 3"
} else if definition == "Internet" {
destinationViewController.titleMsg = "Internet"
destinationViewController.definitionMsg = "definition 4"
} else if definition == "Virtual Reality" {
destinationViewController.titleMsg = "Virtual Reality"
destinationViewController.definitionMsg = "definition 5"
}
}
}
}
}
【问题讨论】:
标签: ios swift if-statement switch-statement