Swift if statement multiple objects, same condition

I have something like the following block. All vars need to fit the same condition, is there a way to shorten this?

@State var var1 = 10
@State var var2 = 10
@State var var3 = 10

if var1 < 15 && var2 < 15 && var3 < 15 {

}

Upvotes: 0

Views: 103

Answers (1)

HunterLion
HunterLion

Reputation: 4006

If the condition is exactly the one you show in your example, it can be shortened as follows:

if max(var1, var2, var3) < 15 {
}

Upvotes: 3

Related Questions