Cannot initialize class object: objective-C

I am trying to make a simple subclass of CCNode, but I cannot create an object.

This gives me the error " * Application termination due to the unselected exception" NSInvalidArgumentException ", reason: '* + [ContentPane <0x206898> init]: cannot initialize the class object.'"

Here is my subclass of CCNode:

#import "ContentPane.h" @implementation ContentPane{ int content[8][4]; CCSprite *_rockPath1; CCSprite *_rockPath2; } - (id)init { self = [super init]; if (self) { CCLOG(@"ContentPane created"); } return self; } 

@end

This is where I try to initiate it:

 - (void)didLoadFromCCB { // tell this scene to accept touches self.userInteractionEnabled = TRUE; _counter = 0; ContentPane *pane = [ContentPane init]; } 
+5
source share
1 answer

A couple of things

In Obj-c, when you want to initialize an object, you need to allocate space for it. This is done using the alloc .

therefore your ContentPane *pane = [ContentPane init];

turns into ContentPane *pane = [[ContentPane alloc] init];

Also, no matter which tutorial you use, stop ... as you stated, your variables, which we call them (iVars), are a very old-fashioned way of doing things, they should really be properties. and Boolean represented by YES and NO not TRUE and FALSE

+18
source

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


All Articles