Search code examples
objective-cobjectautomatic-ref-countingalloc

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


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?


Solution

  • Change

    @property (assign) progress* progressEnergy;
    

    to

    @property (strong) progress* progressEnergy;
    

    so your myObject retains the progress object.