在Swift中,切换语句必须是详尽的,所以我必须在我的默认语句中添加一些内容以保持编译器满意。
private enum TextFieldType: Int {
case street1 = 0
case street2
case street3
case town
case postcode
case phone
case email
}
@IBAction func textFieldEditingChanged(textField: UITextField, forEvent event: UIEvent) {
switch textField.tag {
case TextFieldType.street1.rawValue:
self.model?.address1 = textField.text
case TextFieldType.street2.rawValue:
self.model?.address2 = textField.text
case TextFieldType.street3.rawValue:
self.model?.address3 = textField.text
case TextFieldType.town.rawValue:
self.model?.town = textField.text
case TextFieldType.postcode.rawValue:
self.model?.postcode = textField.text
case TextFieldType.phone.rawValue:
self.model?.primaryPhone = textField.text
case TextFieldType.email.rawValue:
self.model?.email = textField.text
default:
println("")
}
}
在这种情况下(上图),您将如何处理默认语句?为了它而放置println(“”)是不对的。
答案 0 :(得分:3)
您应该使用break
离开switch语句:
default:
break