NSNumber gives wrong int value

◇◆丶佛笑我妖孽 提交于 2019-12-02 12:18:02

问题


I have a program that gets cookies. One param of this cookie is an NSNumber. So I save it to database as

sqlite3_bind_int(addStmt, 2, HEREisNSNUMBER);

Saving this value as:

cookieObj.created = [paramsDictionary valueForKey:@"Created"];

then I create and object of class, and get this parameter into NSNumber; after that, I have a wrong value. For example: In cookie I have a 329822675 after saving this changes to 79931776. How can I correctly save that number?


回答1:


Please try

sqlite3_bind_int(addStmt, 2, [HEREisNSNUMBER intValue]);



回答2:


You are trying to get the int-value of an NSNumber. That's where it goes wrong.

Use this instead: sqlite3_bind_int (addStmt, 2, [HEREisNSNUMBER intValue]); `




回答3:


NSNumber is a reference type. You should not assign it as a int value directly. You should get the intValue of NSNumber and bind it to sqlite3 statement.

sqlite3_bind_int(addStmt, 2, [HEREisNSNUMBER intValue]);


来源:https://stackoverflow.com/questions/6355811/nsnumber-gives-wrong-int-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!