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.
Question
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!
Solution
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.
OTHER TIPS
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).