Reputation: 17278
In some old(ish) Objective-C code base, I accidentally misplaced the opening bracket trying to send a message to an object.
// I meant to type object = [object someEncodingMethod]
[object = object someEncodingMethod];
This compiles and runs just fine, but after this line the original object
variable is not modified. The actual code is trivial to fix, but I'm very curious what this line even means.
Upvotes: 1
Views: 27
Reputation: 64022
Nothing particularly fancy going on. You've assigned the value of object
to the variable object
, and then sent a message to that value. The return value of the called method is thrown away.
I believe any expression that, to the compiler, looks like it evaluates to an object type is legal in the sender position of a message send. And in C, an assignment is an expression that evaluates to the assigned value. (Compare, for example, if( 0 != (result = makeABox()) )
, or closer to home if(( self = [super init] ))
.)
Upvotes: 2