开发者

reading an array

开发者 https://www.devze.com 2022-12-18 00:43 出处:网络
I create random numbers using the following code and store them in an array. NSMutableSet *aSet = [NSMutableSet setWithCapacity开发者_JS百科:6];

I create random numbers using the following code and store them in an array.

NSMutableSet *aSet = [NSMutableSet setWithCapacity开发者_JS百科:6];

while([aSet count]<=6){

    int Randnum = arc4random() % 12;

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

NSArray *arrayOfUniqueRandomNumbers = [aSet allObjects];

Now, I need to read the array to get the values one-by-one using a forloop like

for (int i = 0; i<6; i++);

Can anyone please help me to finish the code?


You can do:

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

精彩评论

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