Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c sqlite数据库中保存的random()整数每次都会更改值_Objective C_Random - Fatal编程技术网

Objective c sqlite数据库中保存的random()整数每次都会更改值

Objective c sqlite数据库中保存的random()整数每次都会更改值,objective-c,random,Objective C,Random,我正在编写一个应用程序,它使用主键在内部sqlite db中保存条目,并使用此键作为userInfo生成LocalNotification 但是如果我从LocalNotification获取密钥并在数据库中搜索它的条目,我什么也找不到。然后,我更改了界面,在标签中看到了密钥,并注意到每次应用程序启动后密钥都在更改 因此,我尝试创建另一个“键”列,并保存了一个 NSInteger *randomNR = (NSInteger*)random() 我喜欢它。但这个数字每次都在变化!因此,我可以复

我正在编写一个应用程序,它使用主键在内部sqlite db中保存条目,并使用此键作为userInfo生成
LocalNotification

但是如果我从
LocalNotification
获取密钥并在数据库中搜索它的条目,我什么也找不到。然后,我更改了
界面
,在
标签
中看到了密钥,并注意到每次应用程序启动后密钥都在更改

因此,我尝试创建另一个“键”列,并保存了一个

NSInteger *randomNR = (NSInteger*)random() 

我喜欢它。但这个数字每次都在变化!因此,我可以复制
random()
方法的实际编号并将其保存到数据库中吗?

您没有正确地从
random()
创建
NSInteger
random(3)
返回一个
long
。您不能简单地在
NSInteger*
中使用long来获得所需的值

您可能会将
NSInteger
与对象混淆
NSInteger
s是基本数据类型,不需要像Cocoa类那样是指针。您可能希望使用:

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

哎呀…我真是个傻瓜。。。一个类铸件(NSInteger*)aNSNumber导致了此故障。。。