ios - NSUserDefaults存取long变量时有问题
怪我咯
怪我咯 2017-04-17 15:44:07
0
2
611

int userid = userId;
[userDefault setInteger:userid forKey:@"userId"];

long userId = [[NSUserDefaults standardUserDefaults] integerForKey:@"userId"];

存的时候userId是id类型。
这时候我取出的数是一个很大的数。请问这是怎么回事?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
Peter_Zhu

Use setObject to save the id variable when saving, and use integerForKey when fetching.

刘奇

The problem is

int userid = userId;

should be changed to

NSInteger userid = userId;
...

Because
NSInteger != int

See picture

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template