-2

I have started implementing a game in cocos2d-iphone; I'm using ARC in my project.

In the main @interface of the class declared in my Levelfinder.h, I have declared the following property:

@property NSMutableArray* pineapples;

In my main class, I am using this property:

for (PineappleModel* pineapple in levelFileHandler.pineapples) 
{
    b2Body* body = [self createPineappleAt:
            [CoordinateHelper levelPositionToScreenPosition:pineapple.position]];
    body->SetLinearDamping(pineapple.damping);
    [pineapplesDict setObject:[NSValue valueWithPointer:body] 
                       forKey:[NSNumber numberWithInt: pineapple.id]];
}

But when I run my code then I'm seeing the following runtime error:

SIGABRT '-[LevelFileHandler setPineapples:]: unrecognized selector sent to instance 0x9431c60

I am new to cocos2d, but have looked at this problem for a long time and am stuck. Any kind of help would be greatly appreciated.


Here is LevelFileHandler.h

@interface LevelFileHandler : NSObject

@property NSMutableArray* pineapples;

@end

Now in my LevelFileHandler.m , i have used my pineapples property like this

self.pineapples = [NSMutableArray arrayWithCapacity:5];
[self.pineapples addObject:pineappleModel]

The intent of this code, clearly, is simply to create an array with a capacity of 5.

Nate Chandler
  • 4,533
  • 1
  • 23
  • 32
shaqir saiyed
  • 732
  • 1
  • 10
  • 36
  • 1
    You aren't calling `setPineapples:` anywhere in this example. Are you sure this is where the error is? – James Webster May 23 '13 at 13:00
  • @james Webster ya buddy , i am damn sure. trying to resolve from last couple of hours :( – shaqir saiyed May 23 '13 at 13:04
  • 1
    Based on the error and the code you are showing, it's very unlikely anyone is going to be able to help you. Please, post more of your related code. Where is "setPineapples" being called? If that's the error it makes sense to actually show the code that calls it. – ezekielDFM May 23 '13 at 13:16
  • I'm guessing the error is in the createPineappleAt call. – Lorenzo Linarducci May 23 '13 at 15:21
  • @ezekielDFM .. i guess error coming based on my property pineapples which i have declared in LevelFileHandler.h .. because i don't have much idea abt how to use properties when ARC is enable ....its missing something like synthesizing Or say Or some default property . – shaqir saiyed May 24 '13 at 05:05
  • @SmugbitStudios i don't think createPineappleAt is issuing this error .that method properly called . – shaqir saiyed May 24 '13 at 05:07
  • 1
    Show your stack trace!!! The trace will tell you exactly where the error is occurring. – Hot Licks May 24 '13 at 14:19
  • Is `LevelFileHandler` the same as your "class called Levelfinder.h"? If not, it sounds like you neglected to add the property `pineapples` to `LevelFileHandler`, but only added it to `LevelFinder`. – Nate Chandler May 24 '13 at 14:30
  • 1
    LevelfileHandler.h >> Header FIle .. & LevelFileHandler is my implemented class ..@NateChandler – shaqir saiyed May 25 '13 at 04:39
  • 1
    @Shaqir: You have not provided enough information for this question to be answered. What line does the debugger indicate when you get the `SIGABRT`? What is the [stack trace](http://stackoverflow.com/a/5476292/1052673) at the time of the crash? Is the `@interface` of `LevelFileHandler` where `pineapples` is declared imported into the source file `LevelFileHandler.m` where the `@implementation` of `LevelFileHandler` appears? Are you getting any warnings during compilation? – Nate Chandler May 25 '13 at 14:47

2 Answers2

1

Well the problem is exactly what is says. You try to call a method on an object of class that does not implement setPineapples. Seems like you try to call setPineapples on a object of type LevelFileHandler, where even class name, doesn't suggest it would have something to do with pineapples :P.

You are not calling this method anywhere in this code snippet. So its hard to judge what exactly is wrong.

Watch out for accidental assignments. Example from UIKit would be

UITextView text = [UITextView alloc] init];
//few lines later, you do this
text = [SomeClass returnStringAsIDType];
//crash sometime later as textView becomes a string.

Since Objective-C is dynamically typed, any assignment that assigns something of an id type to a variable with a wrong class type (if you expect a type other than what has actually been assigned), won't even show a warning. And you can spend many hours scratching your head, wondering why is your UITextView suddenly an NSString, for example.

foFox
  • 1,124
  • 1
  • 14
  • 24
  • right buddy .. i don't have implement any method called SetPineapples . that's my real problem. & i don't have called anything like SetPineapples . – shaqir saiyed May 24 '13 at 05:17
  • 1
    @Shaqir You've got a property called `pineapples` that's not marked `readonly`, so there's an implicit `-setPineapples:` method in whatever class has that property. Setting the property, like `foo.pineapples = somePineaples;` is a call to the `-setPineapples:` method. If this information is new to you, please review the documentation on properties. – Caleb May 25 '13 at 16:07
  • 1
    @Shaqir This code `self.pineapples = [NSMutableArray arrayWithCapacity:5];` is equivalent to `[self setPineapples:[NSMutableArray arrayWithCapacity:5]];`. – Nate Chandler May 25 '13 at 19:40
0

It looks like there is something like [[self class] setPineapples:something] in createPineappleAt:.

Or, perhaps there is problem with atomic reference. Properties are atomic and synthesized by default. Could you try:

@interface LevelFileHandler : NSObject

@property (strong, nonatomic) NSMutableArray* pineapples;

@end
catcyborg
  • 344
  • 1
  • 10
  • I think you're jumping to conclusions here. The OP hasn't provided enough information to tell where the `-setPineapples:` call is occurring. – Caleb May 25 '13 at 16:10