4

I'm 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 ?

Bhavin
  • 27,155
  • 11
  • 55
  • 94
Roger Sanoli
  • 753
  • 10
  • 10
  • 2
    http://stackoverflow.com/questions/7753841/recommended-way-to-declare-delegate-properties-with-arc/7755248#7755248 – beryllium Oct 19 '11 at 12:08

1 Answers1

6

This error is because under ARC ivars default to strong

What this error is telling you that you've declared a property with __unsafe_unretained (assign) ownership, but by default ivar have __strong ownership, so they can't be in one. You can

  1. Omit the ivar, which will be automatically created
  2. Define the ivar to match your (assign) property declaration:

    __unsafe_unretained id <FileListDelegate> delegate;
    
  3. Define the property to match the ivar's implicit __strong ownership:

     @property (weak) id <FileListDelegate> delegate;
    

The three options shamelessly copied from user chrispix's answer in this thread..Credit goes there

Community
  • 1
  • 1
Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167