说我有enum
:
enum TextFieldRule {
case MinLength(length: Int)
case MaxLength(length: Int)
case MatchesOtherTextField(textField: UITextField)
}
可以称为:
.MinLength(length: 1)
有没有办法让外部参数名称不需要?如下所示:
enum TextFieldRule {
case MinLength(_ length: Int)
case MaxLength(_ length: Int)
case MatchesOtherTextField(_ textField: UITextField)
}
并致电:
.MinLength(1)
答案 0 :(得分:4)
param名称不是必需的
enum TextFieldRule {
case MinLength(Int)
case MaxLength(Int)
case MatchesOtherTextField(UITextField)
}
let rule = TextFieldRule.MinLength(1)
switch rule {
case .MinLength(let length):
break
case .MaxLength(let length):
break
case .MatchesOtherTextField(let textField):
break
}