开发者

random() Integer saved in sqlite database changes value everytime

I'm writing an application wich saves entries in the internal sqlite db with a primary key and makes an LocalNotification with this key as the开发者_高级运维 userInfo.

But if I get the key from the LocalNotification and search for its entry in the db, I find nothing. Then i changed the Interface that i see the key in a Label and have noticed that the key is changing after every application start.

So I try to make another "key"column and saved a

NSInteger *randomNR = (NSInteger*)random() 

into it. But this number is also changing everytime! So can I copy the actual number of the random() method and save this to the db?


You're not making an NSInteger from random() correctly. random(3) returns a long. You can't simply cast a long into an NSInteger * and get the value you want.

You may be confusing NSInteger with an object. NSIntegers are primitive data types and don't need to be pointers like Cocoa classes. You probably want to use:

NSInteger randomNR = (NSInteger) random();
NSInteger *randomNRPtr = &randomNR;    // If you really _do_ want a pointer
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜