动态获取数组里面的莫一个元素

    NSArray *array = [[NSArray alloc] initWithObjects:@"1",
                      @"2",@"3",nil];
    NSMutableSet *randomSet = [[NSMutableSet alloc] init];
    
    while ([randomSet count] < 1) {
        int r = arc4random() % [array count];
        [randomSet addObject:[array objectAtIndex:r]];
    }
    
    NSString *str = [randomSet anyObject];

    
    NSLog(@"%@",randomSet);

你可能感兴趣的:(动态获取数组里面的莫一个元素)