This question already has an answer here:
- What does the ^ operator do to a BOOL? 8 answers
Sorry to ask such a simple question but these things are hard to Google.
I have code in iOS which is connected to toggle which is switching between Celsius and Fahrenheit and I don't know what ^ 1 means. self.celsius is Boolean
Thanks
self.celsius = self.celsius ^ 1;
It's a C-language operator meaning "Bitwise Exclusive OR".
Wikipedia gives a good explanation:
XOR
It's an exclusive OR operation.
It's the bitwise XOR operator (see http://www.techotopia.com/index.php/Objective-C_Operators_and_Expressions#Bitwise_XOR).
What it's doing in this case is switching back and forth, because
0 ^ 1
is 1, and1 ^ 1
is 0.