Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

xcode - If condition failing with expression too complex

I have a conditional statement that claims the 'Expression was too complex to be solved in reasonable time. If there are any more than around 5 contains statements in my conditional, it fails with that error. This does not seem like something that should be happening on compile, seeing as the statement isn't all that complex. Is this a bug that anyone else has run into? Is there a solution other than splitting up my conditions?

else if(
                contains(JSONDict.keys.array, "id") &&
                contains(JSONDict.keys.array, "part_number") &&
                contains(JSONDict.keys.array, "sales_part_number") &&
                contains(JSONDict.keys.array, "include_in_search") &&
                contains(JSONDict.keys.array, "description") &&
                contains(JSONDict.keys.array, "brand") &&
                contains(JSONDict.keys.array, "product_group") &&
                contains(JSONDict.keys.array, "product_design") &&
                contains(JSONDict.keys.array, "material") &&
                contains(JSONDict.keys.array, "line") &&
                contains(JSONDict.keys.array, "unit_of_mass") &&
                contains(JSONDict.keys.array, "coating") &&
                contains(JSONDict.keys.array, "pcs_converstion") &&
                contains(JSONDict.keys.array, "appRim") &&
                contains(JSONDict.keys.array, "appSegment") &&
                contains(JSONDict.keys.array, "series") &&
                contains(JSONDict.keys.array, "product_application")
                ){

            }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes that's a known issue - see also this answer.

The solution is to store the logical expression into a variable, using a multiline statement:

else {
    var logicalExpression = contains(JSONDict.keys.array, "id") &&
            contains(JSONDict.keys.array, "part_number") &&
            contains(JSONDict.keys.array, "sales_part_number") &&
            contains(JSONDict.keys.array, "include_in_search")
    logicalExpression = logicalExpression && contains(JSONDict.keys.array, "description") &&
            contains(JSONDict.keys.array, "brand") &&
            contains(JSONDict.keys.array, "product_group") &&
            contains(JSONDict.keys.array, "product_design")
    // ... etc.
    if logicalExpression {
    }
}

A little weird for such a powerful language... but it's a (hopefully temporary) trade off.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...