Automatic Reference Counting Issue: Assigning retained object to unsafe_unretained variable; object will be released after assignment

zeroonnet picture zeroonnet · Mar 5, 2012 · Viewed 10.5k times · Source

I'm getting this warning

"Automatic Reference Counting Issue: Assigning retained object to unsafe_unretained variable; object will be released after assignment"

Here is the code

.h

@interface myObject : NSObject
{
}

@property (assign) id progressEnergy;

@end

.m

@implementation myObject

@synthesize progressEnergy;

-(id)init
{
    if ( ( self = [super init] ) )
    {
        progressEnergy = [[progress alloc] init]; //warning appear on this line
    }

    return self;
}

@end

I have already tried

@property (assign) progress* progressEnergy;

but no luck

Can you please help me figure out what is wrong?

Answer

Wevah picture Wevah · Mar 5, 2012

Change

@property (assign) progress* progressEnergy;

to

@property (strong) progress* progressEnergy;

so your myObject retains the progress object.