1


I have an iOS app that I'm trying to update to take advantage of the A7 64-bit processor.
In many parts of my code, I created integer variables of type int.
Should I change all of them to NSInteger ?
I read many articles on the subject, and I assume I should, but how using extra memory for no reason is good? I mean, all my integer variables will never hold a number greater than 100...

Thanks (:

Noam Solovechick
  • 1,127
  • 2
  • 15
  • 29
  • "how using extra memory for no reason is good?" - in the sense that it's *not bad.* Do those extra 4 bytes really seem wasteful? When you have 1 GB of RAM? (And if we are engaging in horrible premature optimization: it can actually *improve* performance because the compiler won't have to sign or zero extend your `int` when interacting with Apple's `NSInteger`-based APIs...) – The Paramagnetic Croissant Aug 23 '14 at 13:07
  • @TheParamagneticCroissant So using NSInteger somehow actually improves performance? Should I change every single "int" I've ever written to NSInteger? – Noam Solovechick Aug 23 '14 at 13:25
  • Technically, yes, a tiny-tiny bit. But unless you are doing something really hardcore, I doubt it would be noticeable at all. Some people get really emotional about changing every single `int` ever to `NSInteger`, but I don't think that's reasonable. So you can probably start using `NSInteger`, but you don't absolutely have to go back and `sed s/int/NSInteger/g`. – The Paramagnetic Croissant Aug 23 '14 at 13:43
  • @TheParamagneticCroissant Let's say I want to create a for loop. Up until now, I used to do it like this: for(int i = 0; i < 5; i++). Should I now do it with NSInteger, like this: for(NSInteger i = 0; i < 5; i++) ? It's just that I've never seen this syntax before and it's kind of confusing – Noam Solovechick Aug 23 '14 at 14:12
  • This is not new syntax at all. `NSInteger` is just a normal data type, a `typedef`. You don't really have to change all your `for` loops to use it. – The Paramagnetic Croissant Aug 23 '14 at 16:46
  • @TheParamagneticCroissant As I understand for best practice I should though use it. Answer the question instead of commenting so I will mark the question as answered. Thank you (: – Noam Solovechick Aug 23 '14 at 18:58

0 Answers0