-1

Recently I found interesting problem connected with NSNumber initialization.

The difference occurred between simulator (9.3.1) and device (9.3.1).

Let assume that we've got int x = 2; Now we're initializing NSNumber and passing it to a method.

NSNumber *test = [NSNumber numberWithInt:self.x];
[self.method setTestNumber: test];

This two lines had a correct result on both simulator and device.

BUT using only this line

[self.method setTestNumber:[NSNumber numberWithInt:self.x]];

had quite unexpected result. Running it on simulator NSNumber intValue was equal to 2.

Running it on device had incorrect random value. How is that possible? Device is iPad 4 A1458. Also tested on iPad 3 16GB. The same problem occurred. Can you verify this problem?

Piotr Gawłowski
  • 189
  • 1
  • 10

1 Answers1

0

The compiler will actually optimize those two codepaths to the exact same asm. There is no difference between them.

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
  • I will reproduce it later and post exact code/github repo + screenshots showing this effect on side-project. I can't post exact code now because of NDA. – Piotr Gawłowski May 13 '16 at 07:37