I have an array with images of animals, another array with the corresponding animal's sound and the last one with the animal's name. for example:
imagesArray:
0: [UIImage imageNamed:@"Elephant.png"]
1: [UIImage imageNamed:@"Dog.png"]
2: [UIImage imageNamed:@"Cat.png"]
soundsArray:
0: Elephant.mp3
1: Dog.mp3
2: Cat.mp3
wordsArray:
0: Elephant
1: Dog
2: Cat
They are sync and work together with the same counter. I want at start to arrange them randomly in new 3 arrays, but I want the same animal details (image or sound or word) to be the same in all 3 arrays. For example, the new arrays should look like this:
imagesArray:
0: [UIImage imageNamed:@"Cat.png"]
1: [UIImage imageNamed:@"Dog.png"]
2: [UIImage imageNamed:@"Elephant.png"]
soundsArray:
0: Cat.mp3
1: Dog.mp3
2: Elephant.mp3
wordsArray:
0: Cat
1: Dog
2: Elephant
I wrote this code to the view did load:
theNewAnimalsPicture = [NSArray arrayWithObjects:[UIImage imageNamed:@"Square_Bee.png"],[UIImage imageNamed:@"Square_Bird.png"],[UIImage imageNamed:@"Square_Cat.png"],[UIImage imageNamed:@"Square_Chicken.png"],[UIImage imageNamed:@"Square_Cow.png"],[UIImage imageNamed:@"Square_Dog.png"],[UIImage imageNamed:@"Square_Elephant.png"],[UIImage imageNamed:@"Square_Frog.png"],[UIImage imageNamed:@"Square_Horse.png"],[UIImage imageNamed:@"Square_Lion.png"],[UIImage imageNamed:@"Square_Monkey.png"],[UIImage imageNamed:@"Square_Sheep.png"], nil];
theNewAnimalsSound = [NSArray arrayWithObjects:@"Bee.mp3",@"Bird.mp3",@"Miao.mp3",@"Chicken.mp3",@"Cow.mp3",@"Waff.mp3",@"Elephant2.mp3",@"Frog.mp3",@"Horse.mp3",@"LionSound.mp3",@"Monkey_Sound.mp3",@"Sheep.mp3", nil];
theNewAnimalsWord = [NSArray arrayWithObjects:@"Bee",@"Bird",@"Cat",@"Chicken",@"Cow",@"Dog",@"Elephant",@"Frog",@"Horse",@"Lion",@"Monkey",@"Sheep", nil];
for (int i =0;i<[theNewAnimalsPicture count];i++)
{
int number = arc4random() % [theNewAnimalsPicture count];
[PicturesAnimalArray addObject:[theNewAnimalsPicture objectAtIndex:number]];
[SoundsAnimalArray addObject:[theNewAnimalsSound objectAtIndex:number]];
[wordAnimalArray addObject:[theNewAnimalsWord objectAtIndex:number]];
[theNewAnimalsPicture removeObjectAtIndex:number];
[theNewAnimalsSound removeObjectAtIndex:number];
[theNewAnimalsWord removeObjectAtIndex:number];
}
It isn't working. Why is that, and how can I do this in more efficient way than what I did here?