Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.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
Iphone 从plist中选择唯一随机字典_Iphone_Random_Dictionary - Fatal编程技术网

Iphone 从plist中选择唯一随机字典

Iphone 从plist中选择唯一随机字典,iphone,random,dictionary,Iphone,Random,Dictionary,我正在开发一个函数,它允许我从一个.plist中选择一个随机字典,它可以显示一个2字符串的问答,效果很好。但是,有时会选择相同的词典。随机函数是否可以每次显示一个唯一的字典?谢谢 plist: <dict> <key>questions</key> <array> <dict> <key>question</key> <string>q1</string&

我正在开发一个函数,它允许我从一个.plist中选择一个随机字典,它可以显示一个2字符串的问答,效果很好。但是,有时会选择相同的词典。随机函数是否可以每次显示一个唯一的字典?谢谢

plist:

<dict>
<key>questions</key>
<array>
    <dict>
        <key>question</key>
        <string>q1</string>
        <key>answer</key>
        <string>a1</string>
    </dict>
    <dict>
        <key>question</key>
        <string>q2</string>
        <key>answer</key>
        <string>a2</string>
    </dict>
    <dict>
        <key>question</key>
        <string>q3</string>
        <key>answer</key>
        <string>a3</string>
    </dict>
</array>

如果不想两次显示同一词典,请执行以下操作之一:

  • 跟踪您显示的词典。如果再次选择一个,请重试
  • 选择词典时,请将其从选项数组中删除

您是否知道我尝试过的removeLastObject:array和RemoveObjectAtIndex:questionIndex的语法,但都不起作用
    NSString *path = [[NSBundle mainBundle] pathForResource:@"qs" ofType:@"plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

    NSMutableArray *array = [dict objectForKey:@"questions"];

    int questionIndex = arc4random() %[array count];

    NSDictionary *question = [array objectAtIndex:questionIndex];
    NSString *answerStr = [question objectForKey:@"answer"];
    NSString *questionStr = [question objectForKey:@"question"];

    label1.text = answerStr;
    label2.text = questionStr;