I’m getting an analyzer warning, since upgrading…
Returning 'self' while it is not set to the result of '[(super or self) init...]'
Dunno whats wrong with it ?
- (id)initWithFrame:(CGRect)frame {
if (self == [super initWithFrame:frame]) {
[self initLayers];
}
return self;
}
Get rid of the second equals sign. The proper
ifstatement is:The point of this is that the super implementation could return a different, but still valid, object than the current value of self. In this case, your if statement will be false, since the objects are different, and so your initialization won’t occur. However, since it returned a different object, the super implementation should have released the old self, which is what you are returning. This means you are probably returning an invalid pointer.
By using only one equals sign, you set the variable instead of comparing it. Since
if(object)is true ifobjectis notnil, it is equivalent to this:Or, the easier to understand version:
This code reassigns
selfto be the value returned by the super initializer, instead of just assuming the value returned is the same. This is the same reason why it is important to set a variable to the result of theinit...method and notalloc.