Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.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 读取数组_Iphone_Objective C_Nsarray - Fatal编程技术网

Iphone 读取数组

Iphone 读取数组,iphone,objective-c,nsarray,Iphone,Objective C,Nsarray,我使用以下代码创建随机数并将其存储在数组中 NSMutableSet *aSet = [NSMutableSet setWithCapacity:6]; while([aSet count]<=6){ int Randnum = arc4random() % 12; [aSet addObject:[NSNumber numberWithInt:Randnum]]; } NSArray *arrayOfUniqueRandomNumbers = [aSet all

我使用以下代码创建随机数并将其存储在数组中

NSMutableSet *aSet = [NSMutableSet setWithCapacity:6];

while([aSet count]<=6){

    int Randnum = arc4random() % 12;

    [aSet addObject:[NSNumber numberWithInt:Randnum]];
} 

NSArray *arrayOfUniqueRandomNumbers = [aSet allObjects];
NSMutableSet*aSet=[NSMutableSet setWithCapacity:6];
而([aSet count]您可以执行以下操作:

for (NSNumber *val in arrayOfUniqueRandomNumbers) {
    int i = [val intValue];
    ...
}

显然,您只有6个随机数;您不需要使用NSMutableSet,而是将其读入NSArray—直接使用NSArray来存储6个值。
for (NSNumber *val in arrayOfUniqueRandomNumbers) {
    int i = [val intValue];
    ...
}