ios - 如何随机化从字典 plist 中提取的问题

标签 ios dictionary plist

嘿,大家有什么想法可以随机化我从 -plist 文件中提取的问题吗?

-(NSUInteger)nextQuestionID:(NSUInteger)question_number{
return (question_number>=[self.questions count]-1) ? 0 : (question_number+1);
return 0;

}

-(NSDictionary*) getQuestion:(NSUInteger)question_number{
if (question_number>=[self.questions count]) question_number = 0;
return [self.questions objectAtIndex:question_number];
return NULL;


}

最佳答案

要获取随机整数,我建议使用 arc4random 函数,这里有一些代码来执行此操作:

int randomInt = arc4random() % questionNumber;
return [self.questions objectAtIndex: randomInt];

关于ios - 如何随机化从字典 plist 中提取的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262987/

相关文章:

ios - 在 Xcode 的 .plist 中定义 ENUM 值

ios - 如何使用Apple Transport Security保护HTTPS .m4v URL

iphone - CGContext 使用两个不透明的 UIColor 绘制

python - 从按字母顺序排列的列表的索引为 0 的列表字典中对打印输出进行排序

python - 为什么 mydict.items().sort() 不起作用?

python - 嵌套字典 : sum values of same key of the dictionaries nested as a value of dictionary

ios - 如何在快速点击 UITableView 中的一行时获取联系号码(而不是姓名)

ios - 确保两个计时器的执行逻辑不会同时运行

ios - 关于 Metal 中线程组内存的问题

swift - 将 UIImage 保存到 plist 问题(SWIFT)