Frage

I am looking over some code in a new code base and I have come across this line that I am having a hard time processing:

self.button1.hidden = self.button2.hidden = self.button3.hidden = self.button4.hidden = NO;

This isn't very readable to me at all. Is this saying that button1 should be hidden if all of the other buttons aren't hidden?

War es hilfreich?

Lösung

Try breaking it down like this:

self.button4.hidden = NO;

self.button3.hidden = self.button4.hidden; // We just set self.button4.hidden to NO, so this passes that value to self.button3.hidden

self.button2.hidden = self.button3.hidden;

self.button1.hidden = self.button2.hidden;

It's just setting them all to NO in a clever way

Andere Tipps

No, you should read from the right to the left. Button4.hidden is set to NO, then button3.hidden is set to NO, then button2.hidden is set to NO, and then button1.hidden is set to NO.

Finally this is just a strange way to set the hidden property of all this buttons to NO.

They will be assigned in this order:

self.button4.hidden = NO;
self.button3.hidden = self.button4.hidden;
self.button2.hidden = self.button3.hidden;
self.button1.hidden = self.button2.hidden;

This is a great reason why the assignment operator, Type& operator=(const Type& other), returns a reference to itself, so these assignments can be chained together.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top