Can't find interface declaration

Discussion in 'iOS Programming' started by cpuin, Mar 22, 2014.

  1. cpuin macrumors member

    Joined:
    Feb 3, 2013
    #1
    I'm trying to subclass my custom class. I simply add more functionality of SKScene class MyClass and than i want to create more instances of it like Scene0001, Scene0002 etc.

    What i got is the error:Can't find interface declaration for MyScene in superclass of Scene0001

    i import MyScene.h in Scene0001.h

    and in other class i use this:

    Scene0001 *start = [[Scene0001 alloc] initWithSize:self.size];
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Post the complete contents of "Scene0001.h" and "MyScene.h".
     
  3. cpuin thread starter macrumors member

    Joined:
    Feb 3, 2013
    #3
    MyScene.h

    Code:
    #import <SpriteKit/SpriteKit.h>
    #import "DSMultilineLabelNode.h"
    #import "MenuScene.h"
    
    
    @interface MyScene : SKScene
    
    @property (nonatomic, strong) SKSpriteNode *selectedNode;
    
    @end
    


    MyScene.m

    Code:
    
    #import "MyScene.h"
    
    @implementation MyScene
    {
        SKSpriteNode *_rect;
    }
    
    -(id)initWithSize:(CGSize)size{
        if (self = [super initWithSize:size]) {
            /* Setup your scene here */
            
            
            //Set background image.
            SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"bg_military@2x.gif"];
            background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
            background.xScale = 0.5;
            background.yScale = 0.5;
            [self addChild:background];
            
            //button manu button
            SKSpriteNode *menu_back_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_back_button@2x.png"];
            menu_back_button.position = CGPointMake(CGRectGetMidX(self.frame)-130, CGRectGetMidY(self.frame)-268);
            menu_back_button.xScale = 0.5;
            menu_back_button.yScale = 0.5;
            [self addChild:menu_back_button];
            
            //button manu button
            SKSpriteNode *menu_home_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_home_button@2x.png"];
            menu_home_button.position = CGPointMake(CGRectGetMidX(self.frame)-65, CGRectGetMidY(self.frame)-268);
            menu_home_button.name = @"home";
            menu_home_button.xScale = 0.5;
            menu_home_button.yScale = 0.5;
            [self addChild:menu_home_button];
            
            //button manu button
            SKSpriteNode *menu_man_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_man_button@2x.png"];
            menu_man_button.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-268);
            menu_man_button.xScale = 0.5;
            menu_man_button.yScale = 0.5;
            [self addChild:menu_man_button];
            
            //button manu button
            SKSpriteNode *menu_note_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_note_button@2x.png"];
            menu_note_button.position = CGPointMake(CGRectGetMidX(self.frame)+65, CGRectGetMidY(self.frame)-268);
            menu_note_button.xScale = 0.5;
            menu_note_button.yScale = 0.5;
            [self addChild:menu_note_button];
            
            
            //button manu button
            SKSpriteNode *menu_settings_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_settings_button@2x.png"];
            menu_settings_button.position = CGPointMake(CGRectGetMidX(self.frame)+130, CGRectGetMidY(self.frame)-268);
            menu_settings_button.name = @"settings";
            menu_settings_button.xScale = 0.5;
            menu_settings_button.yScale = 0.5;
            [self addChild:menu_settings_button];
            
            
            
            
        }
        return self;
    }
    
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        CGPoint positionInScene = [touch locationInNode:self];
        [self selectNodeForTouch:positionInScene];
    }
    
    
    - (void)selectNodeForTouch:(CGPoint)touchLocation {
        //1
        SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:touchLocation];
        
        //2
    	if(![_selectedNode isEqual:touchedNode]) {
    		[_selectedNode removeAllActions];
    		[_selectedNode runAction:[SKAction rotateToAngle:0.0f duration:0.1]];
            
    		_selectedNode = touchedNode;
            
            //1
    		if([[touchedNode name] isEqualToString:@"home"]) {
    			
                
                MenuScene *start = [[MenuScene alloc] initWithSize:self.size];
                SKTransition *reveal = [SKTransition fadeWithColor:[UIColor clearColor] duration:1];
                [self.scene.view presentScene: start transition: reveal];
                
                [self runAction:[SKAction playSoundFileNamed:@"button_select.mp3" waitForCompletion:NO]];
                
    		}
            
            if([[touchedNode name] isEqualToString:@"settings"]) {
    			
                
                //rect
                _rect = [SKSpriteNode spriteNodeWithImageNamed:@"rectangle@2x.png"];
                _rect.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
                _rect.name = @"rect";
                _rect.xScale = 0.5;
                _rect.yScale = 0.5;
                [self addChild:_rect];
                
                SKLabelNode *text = [[SKLabelNode alloc] initWithFontNamed:@"Times New Roman"];
                text.position = CGPointMake(_rect.xScale+195, _rect.yScale+205);
                text.name = @"close";
                text.text = @"close";
                
                [_rect addChild:text];
                
    		}
            
            if([[touchedNode name] isEqualToString:@"close"]) {
    			
                
                [_rect removeFromParent];
                
                
    		}
            
            //2
    		
            
            
    	}
        
    }
    
    -(void)update:(CFTimeInterval)currentTime {
        /* Called before each frame is rendered */
    }
    
    @end

    Scene0001.h


    Code:
    #import <SpriteKit/SpriteKit.h>
    #import "MyScene.h"
    
    @interface Scene0001 : MyScene
    
    @end

    Scene0001.m


    Code:
    #import "Scene0001.h"
    
    
    @implementation Scene0001
    
    @end
     
  4. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #4
    (Note the posted code does not contain the quoted line.)

    The error message: cannot find interface declaration for 'Foo', superclass of 'Bar' means what it says: that the compiler cannot see an @interface definition for Foo. Or, in other words, the relevant header file has not been #import'ed.
     
  5. cpuin thread starter macrumors member

    Joined:
    Feb 3, 2013
    #5
    Yes, i know what the error means, but i have imported the class in the header as you can see
     
  6. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #6
    Where is that line of code? Do you import the header file?
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    What "other class"?
     

Share This Page