0

This might be a mundane question, but I would like to know the best practice. Since upgrading to Xcode 5.1, I got a ton of warnings about loss integer precision from NSInteger (aka 'long') to 'int' assuming because of the arm64 switch.

I have been type casting so far to get rid of the warning for example:

int number = (int)[self.arrayOfUsers count];

or should I just use

long number = (int)[self.arrayOfUsers count];

Which is "better"? Should I be mostly using longs now?

Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Alan
  • 9,331
  • 14
  • 52
  • 97

2 Answers2

6

What you should be doing is using the correct data type:

NSUInteger number = [self.arrayOfUsers count];

Don't needlessly cast to something like int. Use the proper type.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

Simply use the same type if you can:

NSUInteger number = [self.arrayOfUsers count];

Your first suggestion:

int number = (int)[self.arrayOfUsers count];

would also work fine as long as you're sure, that the array's count will never go over the integer limit (2^31-1).

DrummerB
  • 39,814
  • 12
  • 105
  • 142