Protocols and property assignment in iOS 5

I am trying to create my own custom delegates in iOS 5 . In iOS 4, I usually used the Assign property:

@property(nonatomic, assign) id<AnyProtocol> delegate; 

Now, when I try to synthesize , I get the following error message:

 error: Automatic Reference Counting Issue: Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be __unsafe_unretained 

Any ideas?

+4
source share
1 answer

This error is due to the fact that by default ivars uses strong

That this error tells you that you declared the property with __unsafe_unretained (assign) ownership, but by default ivar has __strong ownership, so they cannot be in one. You can

  • Omit ivar to be automatically created
  • Define ivar to match the declaration of the property (assign):

     __unsafe_unretained id <FileListDelegate> delegate; 
  • Define a property to match the implicit __strong ivar:

      @property (weak) id <FileListDelegate> delegate; 

Three options shamelessly copied from the user chrispix answer in this thread .. The loan goes there

+6
source

All Articles