To answer your question. If you look in the documentation for NSNumber isEqualToNumber: function you will notice the following line,
Two NSNumber objects are considered equal if they have the same id values ββor have equivalent values
It is important that you understand this. In your code that you specify, my NSNumber object "number" is equal to "value", you are not asking if the numerical value stored in my NSNumber object is "number", the numerical value stored in my NSNumber object is "value".
The last line of code you wrote shows that in fact your numerical NSNumber values ββare actually equal.
NSLog(@"%d", [number unsignedLongLongValue] == value);
So, you correctly store and retrieve the values, you should use the comparison method == with NSNumber objects that store numerical values ββ(i.e. intValue == intValue, unsignedLongLongValue == unsignedLongLongValue) and do not compare their object identifier together.
Regarding this line of code
NSLog(@"Current Number:%@", number);
This is not strange, this is completely normal, since you told NSLog to print the NSObject 'number' view. I am not 100% sure, but I believe that the NSNumber - ( NSString * ) description
function by default returns an unsigned int value for the numerical value it contains. That is why you get a large negative number. You can look at the function NSNumber - (NSString *)descriptionWithLocale:(id)aLocale
to print the data more logically for you, or you could use
NSLog(@"Current Number:%llu", [number unsignedLongLongValue]);
Which will give you the correct answer.
EDIT:
In addition to this, having considered what is happening, it is that when you recall your NSNumber object from UserDefaults, its original type of number is not saved (this information is highlighted in the documentation for NSNumber in the overview section)
(Note that numeric objects do not necessarily preserve the type with which they are created.)
You can verify this yourself if you register the following after extracting the "number" from the user default values ββ(add this to the end of the code that you have in your question) and look at the encoding values ββshown here
NSLog(@"%s", [number objCType]);
The difference between Q and q is that Q is an unsigned value ... therefore, why are you having problems with the isEqualToNumber function: how the types of numbers are different. If you're so dead using the iSEqualToNumber: function to compare values, you can implement this to get your value from NSUserDefaults.
NSNumber *number = [NSNumber numberWithUnsignedLongLong:[[NSUserDefaults standardUserDefaults] objectForKey:NumberKey] unsignedLongLongValue]];
You can look at how to use the NSNumber compare function: see if the return value is NSOrderedSame, however this will not work to compare unsigned and signed values ββof the same type, so in your situation, I would use the above as getting data from NSUserDefaults cancels " signature "of your number.