Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个这样的数组。
NSArray *myArray = [NSArray arrayWithObjects:@"1",@"3",@"5",@"45",@"67",nil];
我想从我的数组中选择一个随机值并将其放入标签中。
我该怎么做?
做这个
myLabel.text = myArray[arc4random_uniform(myArray.count)];
并且(现在不是唯一的)正确的解决方案:
NSArray *array = @[@"foo", @"bar", @"baz"]; NSString *item = array[arc4random_uniform(array.count)];