1
这就是我想要做的事。每次我的viewDidLoad开始时,获取7个随机,非重复的数字。我得到了它的创建随机量,但我一直在试图清除的NSMutableSet加载时得到一组全新的,我有麻烦了。 NSLog清楚地显示NSMutableSet中没有任何内容,但它总是以相同的顺序出现相同的数字?无法清除/重置NSMutableSet?
// Create set
NSMutableSet *mySet = [NSMutableSet setWithCapacity:6];
// Clear set
NSMutableSet *mutableSet = [NSMutableSet setWithSet:mySet];
[mutableSet removeAllObjects];
mySet = mutableSet;
NSLog(@"mutableSet: %@", mutableSet); // Shows nothing
NSLog(@"mySet: %@", mySet); // Shows nothing
// Assign random numbers to the set
while([mySet count]<=6){
int Randnum = arc4random() % 7+1;
[mySet addObject:[NSNumber numberWithInt:Randnum]];
}
NSLog(@"mySet1: %@", mySet); // Always shows 5,1,6,2,7,3,4 ???
我喜欢的阵列版本要好很多。谢谢! – user1467534 2014-09-15 17:25:34