Search code examples
iosiphoneobjective-cnsarrayuicolor

How to pick randomly UIColor saved in NSArray?


I saved colors in a NSArray like this:

NSArray *arr = [[NSArray alloc] initWithObjects:[UIColor blackColor], [UIColor darkGrayColor], nil];

The problem is that I don't know how to pick randomly the UIColor from this NSArray.

How to do this?

Thanks in advance.


Solution

  • [arr objectAtIndex:arc4random() % arr.count];