Xcode 7.3b4, non-arc, cannot create __weak reference

Using sample new app code, disabling ARC, and adding this line to create a weak self (see screenshot and attached sample code):


__weak AppDelegate* weakSelf = self;


using latest stable Xcode release 7.2.1, it's working fine.


But on latest Xcode beta 7.3b4, it's giving me the error:


AppDelegate.m:22:3: error: cannot create __weak reference in file using manual reference counting __weak AppDelegate* weakSelf = self;


Is this a new feature/bug of XCode 7.3b4?
Is this documented anywhere?


Thanks.

Accepted Reply

Erm, was there ever such a thing as a weak variable reference under MRR? "__weak" means one or both of two things:


1. An unowned reference (i.e. not representing a retain count).


2. A zeroing reference (i.e. that the runtime zeroes when the referenced object is deallocated).


#1 doesn't apply to MRR, because you just don't retain the variable anyway.


#2 doesn't apply to MRR either, because the runtime support is in GC and ARC, which you're not using.


It sounds like the compiler is now just complaining that it can't do what it could never do. (And in the case of an app delegate, you wouldn't be able to tell the difference at run-time, since the app delegate generally is never deallocated.)

Replies

Erm, was there ever such a thing as a weak variable reference under MRR? "__weak" means one or both of two things:


1. An unowned reference (i.e. not representing a retain count).


2. A zeroing reference (i.e. that the runtime zeroes when the referenced object is deallocated).


#1 doesn't apply to MRR, because you just don't retain the variable anyway.


#2 doesn't apply to MRR either, because the runtime support is in GC and ARC, which you're not using.


It sounds like the compiler is now just complaining that it can't do what it could never do. (And in the case of an app delegate, you wouldn't be able to tell the difference at run-time, since the app delegate generally is never deallocated.)

Thanks for the information QuincyMorris!

Looks like we'll have to update our code on our end or transition to ARC.


Answer from Apple:


This issue behaves as intended based on the following: We are in the process of implementing weak references in all Objective-C language modes. Since “__weak” has historically been ignored in non-ARC (and non-GC) language modes, we’ve added this error to point out places where the semantics will change in the future. Please update your bug report to let us know if this is still an issue for you.

Please set 'Weak References in Manual Retain Release:YES'.