How to use delegates with automatic reference counting

I jumped on the bandwagon ARC. Previously, I would have rights to delegate properties as follows:

@property(assign) id<MyProtocol> delegate; 

So, I thought I would do it under ARC:

 @property(weak) id<MyProtocol> delegate; 

Not this way. In the @synthesize statement in .m, I have error compilation:

* Semantic release: existing ivar 'delegate' for __weak property 'delegate' must be __weak *

I declared it weak! Just like passing a class that implements the protocol to a low reference property. Should I wrap it in one of these strange obj_unretained calls?

Any help on this would be greatly appreciated.

+44
ios iphone automatic-ref-counting ios5
Jun 30 2018-11-11T00:
source share
1 answer

"ivar" means an "instance variable" that you did not specify. I'm sure it looks something like this:

 @interface Foo : NSObject { id delegate; } @property (weak) id delegate; 

What the error means is that it should look like this:

 @interface Foo : NSObject { __weak id delegate; } @property (weak) id delegate; 

If a property claims to be weak, ivar, in which the value is stored, must also be weak.

+65
Jun 30 '11 at 2:01
source share



All Articles