Isaac
Isaac

Reputation: 10834

Do Objective-C blocks capture the property value or the object value?

Let's suppose I have an instance anInstance of some class that has a property aProperty. When I use anInstance.aProperty inside a block, does the block capture the (pointer) value of anInstance and then send the aProperty message to that captured (pointer) value or does the block only capture the value of anInstance.aProperty?

Upvotes: 2

Views: 482

Answers (1)

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

The block will capture anInstance here. Remember that property accesses are just message sends.

If you think about it as [anInstance aProperty] it may be more obvious. But to note, anInstance->someIvar still captures anInstance and not the iVar.

Upvotes: 6

Related Questions