Instance variable used while self is not set as a result

I am working with SGAREnvioroment and I am getting the following error:

Instance variable used when "I" is not set by the result "[(super or self) init ...] '

In this code snippet:

@interface SG3DOverlayView (Private) - (id) initGLES; - (void) drawView; - (BOOL) createFramebuffer; - (void) destroyFramebuffer; - (void) clearTouches; @end @implementation SG3DOverlayView + (Class) layerClass { return [CAEAGLLayer class]; } -(id) initWithFrame:(CGRect)frame { if(self = [super initWithFrame:frame]) { self = [self initGLES]; } return self; } -(id) initGLES { self.multipleTouchEnabled = YES; self.exclusiveTouch = YES; CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer; eaglLayer.opaque = YES; eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) { [self release]; return nil; } self.backgroundColor = [UIColor clearColor]; mainSubview = [[UIView alloc] initWithFrame:self.frame]; mainSubview.backgroundColor = [UIColor clearColor]; animationInterval = 1.0; pinchTimer = nil; dragging = NO; currentSphereRadius = 0.0; [self clearTouches]; return self; } 

I get an "error" here:

 if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) { 

But, as you can see, self adjusts to -(id) initWithFrame:(CGRect)frame , and -(id) initGLES is private, so it is always called from -(id) initWithFrame:(CGRect)frame .

So maybe I need to do something to fix this?

+4
source share
2 answers

Not the prefix of the name of your function with init - the analyzer assumes that it is an initializer, and in this case it is not.

In addition, a function should not return self unless it initializes it. Make it invalid.

+9
source

Source: https://habr.com/ru/post/1382865/


All Articles