Instance variable used while 'self' is not set to the result of '[(super or self) init…]' via Analyzer

StackOverflow https://stackoverflow.com/questions/9854248

Question

When i test my code via Analyzer then got:

Instance variable used while 'self' is not set to the result of [(super or self) init…]

My code:

self = [super init];//initWithFrame:frame];
if (self) 
{
    tickerSymbol = [object valueForKey:@"TickerSymbol"];
    url = [object valueForKey:@"URL"];
    rssFeed = [object valueForKey:@"RSSFeed"];

    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ClientInfoView" 
                                                             owner:nil 
                                                           options:nil];
    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[ClientInfoView class]])
        {               
            self = (ClientInfoView *)currentObject;
            break;
        }
    }
    [self.clientNameLabel setText:[clientObject valueForKey:@"Name"]];
    [self.symbolLabel setText:[object valueForKey:@"TickerSymbol"]];

    //[self loadHistoricalInfo];
    self.getStock = [GetStockValue stockValueWithDelegate:self];
    [self loadInfo:object clientObject:clientObject];
    [self layoutLabels];

}

return self;
Was it helpful?

Solution

            self = (ClientInfoView *)currentObject;

That doesn't make any sense. You should never be re-assigning self save for to the result of [super init...] (and in the case of some advanced techniques, which this isn't).

You should also never need to grub through the IB file like that. Create an outlet and make a connection, then use the outlet directly in your code.

Note that, in general, you shouldn't load interface in init methods.

OTHER TIPS

It's because of self = (ClientInfoView *)currentObject;. I think there's some confusion as to how to connect to your object from within your nib. Instead of instantiating an object within the nib file and trying to swap your object for it, try connecting to File's Owner from within your nib, and then set yourself as the owner:

NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ClientInfoView" 
                                                         owner:self 
                                                       options:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top