Reputation: 1019
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
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 Int
s, 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 ==
:
Upvotes: 1