I can properly assign and retrieve a positive integer to an attribute of a managed object model instance. However, assigning a negative integer to this attribute records the number “4294967295” to my core data persistant store (an xml file). Thus, when the application reloads and the managed object is re-instantiated, the attribute reads “4294967295”.
This attribute is specified in my DataModel as type Integer 32 and has a “Min Value” of “-12”. I’m guessing this has something to do with storing negative integers as strings. This code produces the same “4294967295”:
NSLog(@"Log -1: %u", -1);
=> "Log -1: 4294967295"
What’s the proper way to store a negative integer in Core Data?
It’s not a problem with Core Data, it’s a problem with your format specifier.
%umeans that you want the argument formatted as an unsigned integer, which cannot be negative. Use%dor%iinstead (these mean signed integers).