Saurabh Bisht
Saurabh Bisht

Reputation: 408

Instance variable & properties in blocks

All objects are in the heap, that is obvious, but what about the instance variables? Do they change the retain count? If yes, can they be directly used and modified in blocks?

I came across a tutorial which says blocks can modify objects that are in the heap. So another question arises: Can we modify a heap object without using __block before the object type?

Upvotes: 1

Views: 250

Answers (1)

Duncan C
Duncan C

Reputation: 131501

You don't need the __block qualifier in order to modify instance variables. You were on the right track in thinking about this. If a thing is on the heap, it's persistent. If it is stack based, like a local variable, it does need to be marked with __block if the block modifies it.

Upvotes: 2

Related Questions