Receive bytes in both cases and retest how many of them are equal.
uint8_t* bytes1 = (uint8_t*)[object1 bytes]; uint8_t* bytes2 = (uint8_t*)[object2 bytes]; NSUInteger sameCount = 0; for (NSUInteger i = 0 ; i < MIN([object1 length], [object2 length]) ; ++i) { if (bytes1[i] == bytes2[i]) { sameCount++; } } double fractionSame = (double) sameCount / (double) MIN([object1 length], [object2 length]);
The above assumes that if one of the data is longer than the other, you do not care about the excess.
source share