简体   繁体   中英

Integer store value is negative

I have a Core Data model that contains an id field which is a Integer 16 .

I noticed that the app was saving some object with a negative value in that field

For instance (from sqlite3 command line):

2|1|1|-32223||9|424968994|424968994|step`

I thought I'd switch to Integer 32 in order to fix it but the problem still remains. Object are still saved with a negative value in that field. I'm not quite sure why.

Was that right to switch to Integer 32 ? Should have this fixed the problem?

Edit: Example of value I want to save

For example the value I am storing is 33239 but it's saved as -32297

由于unsigned longInteger32Integer64兼容,您应该传递这种类型的 var ( unsigned long ) 以保存在CoreData

I have a similar issue.I am storing the 33675 integer value in CoreData but when i retrieve i got value like -26532.

In My case i defined my integer value as type int16 so range of int16 is -32,768 to 32,767 when i change my variable from int16 to int64 its resolved my issue.

for reference : Swift - Data Types
在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM