I have multiple arrays and i wish to check if the string selcted by random from one array is in another array and if so show an image
I have globaly set plistarray1 and plistarray2 in the h file and in the m file i have the following
The last block of code is what im strugling with i cant get an image to display based on the random string generated from plistarray.
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
NSString *path = [[NSBundle mainBundle] pathForResource:
@"data" ofType:@"plist"];
if ([[defaults objectForKey:@"truthonoff"] isEqualToString:@"YES"] && [[defaults objectForKey:@"dareonoff"] isEqualToString:@"YES"] ) {
self.text.text =@"Are you ready for this?";
[Animations fadeIn:self.text andAnimationDuration:1.0 andWait:YES];
NSDictionary *plistDict1 = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray * plistArray1 = plistDict1[@"truth"];
NSDictionary *plistDict2 = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *plistArray2 = plistDict2[@"dare"];
self.plistArray = [[plistArray1 arrayByAddingObjectsFromArray:plistArray2] mutableCopy];
}
else if ([[defaults objectForKey:@"truthonoff"] isEqualToString:@"YES"] ) {
self.text.text =@"I hope you are feeling brave!";
[Animations fadeIn:self.text andAnimationDuration:1.0 andWait:YES];
NSDictionary *plistDict3 = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *plistArray3 = plistDict3[@"truth"] ;
self.plistArray = [plistArray3 mutableCopy];
NSLog(@"%@", plistArray);
}
else if ([[defaults objectForKey:@"dareonoff"] isEqualToString:@"YES"] ) {
self.text.text =@"This could be interesting!";
[Animations fadeIn:self.text andAnimationDuration:1.0 andWait:YES];
NSDictionary *plistDict4 = [[NSDictionary alloc] initWithContentsOfFile:path];
NSMutableArray *plistArray4 = plistDict4[@"dare"];
self.plistArray = [plistArray4 mutableCopy];
NSLog(@"%@", plistArray);
}
else {
self.text.text =@"Please turn on Truth or Dare";
[Animations fadeIn:self.text andAnimationDuration:1.0 andWait:YES];
}
////display random quote from array
int randV = arc4random() % self.plistArray.count;
NSLog(@"%@", plistArray);
self.text.text = self.plistArray[randV];
[self.plistArray removeObjectAtIndex:randV];
[Animations fadeIn:self.text andAnimationDuration:1.0 andWait:YES];
//display truth or dare image
if ([plistArray containsObject:plistArray1]) {
// selectedString is from the truth array
self.truthimage.hidden = NO;
}