14

I really don't understand what's going on here.

I have a function that is getting the first 3 bytes from an NSData object, receivedStream, and putting them into another NSData object, temp, via a char array. Then comparing that to an NSData object created from a char array buffer. Both new NSData objects are created and have the correct contents. However, when isEqualtoData is called, I get an error:

[NSConcreteData isEqualtoData:]: unrecognized selector sent to instance (instance refers to tmp2)

I also get the warning

Instance method '-isEqualtoData:' not found (return type defaults to 'id')

which I don't understand as it's clear that this is a valid method in the docs. Do I need to declare NSData.h somewhere?

-(BOOL)checkHeader{
    char tmp[3];
    [receivedStream getBytes:&tmp length:3];
    NSData *temp = [NSData dataWithBytes:tmp length:3];
    NSData *tmp2 = [NSData dataWithBytes:header length:3];
    BOOL test = [tmp2 isEqualtoData:temp];
    return test;
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Stev_k
  • 2,118
  • 3
  • 22
  • 36
  • Just edit the post, man. I made a copy&paste of your code and took me 10 minutes to figure out what was wrong xD – falkon21 Jan 22 '16 at 10:01

1 Answers1

32

The method is called isEqualToData:. Note the capital T – Objective-C is case-sensitive, as most programming languages.

omz
  • 53,243
  • 5
  • 129
  • 141
  • I knew it was going to be something stupid like that. Thanks. That'll teach me to copy the method straight from the docs. – Stev_k Oct 23 '11 at 00:06