1

I was not expecting that hash on NSString returns differently depending on the target device.

NSLog(@"%lu", (unsigned long)[@"test" hash]);
// 38178019076 on my iPad.
// 3818280708 on my iPhone and (iPhone/iPad-)Simulator.

Apart from the fact that hash on NSString should be used with care (hash is bad with NSString) and this problem can easily be solved using a real hash (e.g. sha), I am interested why different results are returned?

Masa
  • 3,241
  • 1
  • 16
  • 12
  • 2
    Perhaps you've got a 32-bit iPad and a 64-bit simulator (=Mac)...? –  Dec 19 '13 at 20:13

1 Answers1

5

The NSObject protocol hash method returns an NSUInteger. NSUInteger is of varied type based on the architecture of the device (32 or 64 bit). It's probably that the hash implementation is different for 64 bit devices versus 32 bit devices (using the additional space to make more accurate hashes).

Fruity Geek
  • 7,351
  • 1
  • 32
  • 41
  • Thank you. My setup was iPad Air (64 bit), iPhone 5 (32 bit) and I just tested it on the 32-bit Simulators. So one more reason to use that function with care... – Masa Dec 19 '13 at 20:21