Ryan
Ryan

Reputation: 1019

syntax, == operator when not in if statement.

I came across this line of code

let shouldExpandWindow = self.itemsOffset + self.items.count == self.windowOffset + self.windowCount

I'm not used to seeing == outside of an if statement. I know that it's meant for comparisons. But how would it work in this case. Thank you

Upvotes: 1

Views: 53

Answers (1)

vacawama
vacawama

Reputation: 154563

== is a function that takes two values of the same type (such as Int) and returns a Bool. For example, if you are comparing two Ints, the function signature is:

func ==(lhs: Int, rhs: Int) -> Bool

The result of the comparison is then assigned to shouldExpandWindow which Swift infers to have the type Bool.

You can find this out for yourself by option-clicking on ==:

enter image description here

Upvotes: 1

Related Questions