NSNumberFormatter wrongfully displays 16-bit unsigned int as signed

Hi all, My interface displays a text field bound to an NSNumber that I use internally as unsigned int. That NSNumber is actually saved with Core Data as Integer 16. However, the interface displays the number signed, meaning anything above 32.768 is actually shown to be negative.

I couldn't find a way to force my NSNumberFormatter to display unsigned numbers. Setting the minimum value to 0 also doesn't work, since internally it's gonna be positive anyway.

Could you help me display my 16-bit integer as an unsigned int between 0 and 65.535?

I am building a macOS app using Objective-C, macOS SDK 10.14 and Xcode 14.3.1.

Replies

Search for Integer 16 in the Developer Documentation in Xcode. You'll see a Core Data enumeration case for NSInteger16AttributeType and it says it's "An attribute that stores a 16-bit signed integer value".

So, if your attribute in your Core Data model is Integer 16 then you're storing a signed integer value.

A signed integer 16 has a value of -32,768 to +32,767, so perhaps you need to use an Integer 32 or 64 in your model?