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