Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSData isEqualtoData

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;
}
like image 587
Stev_k Avatar asked Oct 22 '11 23:10

Stev_k


1 Answers

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

like image 161
omz Avatar answered Oct 20 '22 00:10

omz