3 ms·
It should. [obj1 doWithSideEffects] will be evaluated before [obj2 do] because Obj-C is eager, so the runtime doesn't know (or care) about obj2 when
by masklinn 17y ago
It should.
[obj1 doWithSideEffects]
will be evaluated before
[obj2 do]
because Obj-C is eager, so the runtime doesn't know (or care) about obj2 when it considers the evaluation of the inner expression.
To get the behavior you want, you need to use blocks (which incidentally were introduced in 10.6) and write something along the lines of:
[obj2 do: ^{ [obj1 doWithSideEffects] }]
In this case, if obj2 do: doesn't explicitly evaluate the block, obj1 doWithSideEffects won't be evaluated.