You have discovered that NSNumber (actually, its CFNumber counterpart) has a cache for integers between -1 and 12 inclusive. Take a look at the CFNumberCreate
function in CFNumber.c
to see how it works.
It looks like you can force it not to use the cache by passing your own allocator to CFNumberCreate
. You'll need to look at the CFAllocator
documentation.
But note that the CFNumberCreate
manual says this:
The
theType
parameter is not necessarily preserved when creating a newCFNumber
object.
So even if you bypass the cache, you might not get back an object whose objCType
is q
(which means long long
). It looks like the current implementation will return q
but that could change in a future version.
You are allowed to write your own NSNumber
subclass if you need to guarantee that objCType
returns q
. Read “Subclassing Notes” in the NSNumber Class Reference.