2

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?

Isaac
  • 10,668
  • 5
  • 59
  • 68
  • It keeps the instance. You can read this http://stackoverflow.com/questions/7853915/how-do-i-avoid-capturing-self-in-blocks-when-implementing-an-api [1]: http://stackoverflow.com/questions/7853915/how-do-i-avoid-capturing-self-in-blocks-when-implementing-an-api – Daniel Oct 18 '12 at 16:29

1 Answers1

6

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.

Joshua Weinberg
  • 28,598
  • 2
  • 97
  • 90
  • That's definitely the behavior I'd expected, but some strange errors I was seeing (related to CoreData, managed object contexts, and persistent stores) led me to wonder whether I might have misunderstood or if the compiler might be doing something different/tricky because of the dot notation. – Isaac Oct 18 '12 at 16:29