Beto
Beto

Reputation: 3438

What is wrong with definition of this method? (Objective-C)

I suppose this is easy a simple question but not for me. I’m in a loop and i can not see the answer.

I try to access a method inside an object but I get this message:

-[SKSpriteNode playWordSound]: unrecognized selector sent to instance 0x7fbd75e52a60
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SKSpriteNode playWordSound]: unrecognized selector sent to instance 0x7fbd75e52a60' ***

My code looks like:

Word.h

#import <SpriteKit/SpriteKit.h>

@interface Word : SKSpriteNode

- (instancetype)init;
- (void)playWordSound;

@end

Word.m

#import "Word.h"

@implementation Word 

- (instancetype)init {
if (self = [super init]) {
    [self createWord];
    // some physics here
}
return self;
}

// Crear la ball con el word
- (void)createWord {

// some code here
}

- (void)playWordSound {
// some code to play a sound
}

And the code to call in MyScene is:

- (void)didBeginContact:(SKPhysicsContact *)contact {
  // …
  if (other.categoryBitMask & PCWordCategory) {
        Word *wordEffect = (Word *)other.node;
        [self flyAwayWord:wordEffect];
        // HERE IS THE ERROR —
        [wordEffect playWordSound];
        // HERE IS THE ERROR -
        wordEffect.physicsBody = nil;
   }
  // …

}

What is wrong with definition of this method. Sorry but I can not see some obvious.

Upvotes: 1

Views: 39

Answers (1)

vien vu
vien vu

Reputation: 4337

you cast wrong type:

Word *wordEffect = (Word *)other.node;

You think it is Word but actually it is

SKSpriteNode

Upvotes: 1

Related Questions