NSInteger is integer object. So surely there should be long object?
Asked
Active
Viewed 768 times
-2
-
3NSInteger is not an object. It is a primitive type – Andrey Chernukha Jan 10 '17 at 15:46
-
NSInteger is not an object? Ah yes, I got mixed up with NSNumber. – GeneCode Jan 10 '17 at 15:59
-
that's a common mistake – Andrey Chernukha Jan 10 '17 at 16:00
-
I wish they are named differently. Like CGInteger or something. NS normally is for objects. – GeneCode Jan 10 '17 at 16:03
-
@GeneCode The `NS` prefix is for everything that commonly comes from the Foundation and AppKit frameworks — including things like `NSRect`, `NSPoint`, and other C types and structs. `CG` is the prefix for the CoreGraphics framework, which is unrelated. – Itai Ferber Jan 10 '17 at 16:08
-
@ItaiFerber ok. – GeneCode Jan 11 '17 at 02:32
2 Answers
5
NSInteger
and NSUInteger
are platform specific, so on 32 bit system is declared as an int and on 64 bit system it is declared as a long.

rckoenes
- 69,092
- 8
- 134
- 166
-
So if 4billion is held by NSInteger, it works on 64bit and overflow on 32bit? – GeneCode Jan 10 '17 at 15:58
-
-
-
1Well it allows you code to be future proof, why use 32bit int on a 64 bit system. But if you know before hand that you need to store a large number you should a type that can hold it. – rckoenes Jan 10 '17 at 16:06
-
Yea. That's what I mean. We should always know beforehand the range of the number that we're gonna use. – GeneCode Jan 11 '17 at 02:33
1
NSInteger is a foundation type, as you can see here.
There are also other useful primitive types, like NSRect, NSSize, etc.
Apple simply chose not to have a NSLong or NSLongLong type defined in foundation.
More information as to when to use NSInteger (and what the considerations are behind them) can be found in this related question.

Community
- 1
- 1

Michael Dautermann
- 88,797
- 17
- 166
- 215