The question of whether __unsafe_unretained
is needed comes down to whether there would be a retain cycle otherwise. We know that if it were a strong reference, then the block would retain observer
. The question then is, does observer
retain the block (or even, may it be the block itself)?
This is a question that cannot be answered from first principles. It requires knowing what the observer
object is and what it does internally. Unfortunately, this is an opaque object that Apple does not tell us much about, other than that we must use it to remove the observer. The documentation does not say anything about what this object is or may retain internally. I believe this is a serious omission from the documentation.
From other StackOverflow answers, e.g. this and this, it appears empirically that if a weak reference (__weak
or __unsafe_unretained
) from the block to the observer is not used, a retain cycle results. Therefore, we can conclude that the observer
object retains (or, is) the block.