Swift:表达式太复杂,无法在合理的时间内解决

时间:2015-03-02 17:36:00

标签: ios swift

现在,我已经看到遍布stackoverflow的这个快速错误。但是,他们处理它的方式在我的情况下似乎不起作用。

if ( 
        fieldType == "checkbox" ||
        fieldType == "time" ||
        fieldType == "birthdate" ||
        fieldType == "datetime" ||
        fieldType == "phone" ||
        fieldType == "payment" ||
        fieldType == "stripe" ||
        fieldType == "paypal" ||
        fieldType == "paypalpro" ||
        fieldType == "address" ||
        fieldType == "2co")

{

我不确定如何解决它。必须有某种方法来降低它的复杂性。

1 个答案:

答案 0 :(得分:0)

我要做的只是从一系列文字开始:

    let fieldType = "Howdy"
    let possibilities = ["checkbox","time"] // ... add the others too...
    if find(possibilities, fieldType) != nil { // or: if contains(possibilities,fieldType)
    }