Search code examples
objective-ciosinstanceretainanalyzer

ios initialize an instance inside a function to use outside


the xcode analyzer tell me that a method returns an Objective-C object with a +1 retain count: enter image description here

but the self.athletes is an object that I need also outside my function... how can I solve this 'warning? thanks again

the athletes is declared like this:

NSMutableArray *athletes;
@property (nonatomic, retain) IBOutlet NSMutableArray *athletes;

Solution

  • Replace that line with this one:

    self.athletes = [NSMutableArray array];
    

    I wrote full explanation here : Memory Management for properties with retain attribute