linking elements from three different arrays in Objective-C
I am trying to make a matching game for learning arabic. I have populated 3 different arrays from 3 plists and I am using a UIPicker to display the information. Between the population of the array and the transfer to the UIPickerView, I've shuffled the elements of the array. Unfortunately, this causes me to lose track of the initial index of the items in the array. I need to be able to recall each elements' initial index in order to check for a match as each element in the plists are listed in the same order (with different languages).
I use the following shuffle algorithm:
int randomSort(id obj1, id obj2, void *context ) {
// returns random number -1 0 1
return (arc4random()%18-9);
}
- (void)shuffle {
// call custom sort function
[list sortUsingFunction:randomSort context:nil];
[list2 sortUsingFunction:randomSort context:nil];
[list3 sortUsingFunction:randomSort context:nil];
}
and the following initialization:
NSString *arabicword = [[NSBundle mainBundle] pathForResource:@"arabicword" ofType:@"plist"];
NSString *englishword = [[NSBundle mainBundle] pathForResource:@"englishword" ofType:@"plist"];
NSString *pronunciation = [[NSBundle mainBundle] pathForResource:@"pronunciation" ofType:@"plist"];
list = [[NSMutableArray alloc] initWithContentsOfFile:arabicword];
list2 = [[NSMutableArray alloc] initWithContents开发者_运维问答OfFile:englishword];
list3 = [[NSMutableArray alloc] initWithContentsOfFile:pronunciation];
any suggestions? any help will be much appreciated :]
Instead, create a new class:
@interface Word : NSObject
@property (readonly) NSString *english;
@property (readonly) NSString *arabic;
@property (readonly) NSString *pronunciation;
@end
(The complete implementation is left to the reader.)
Use instances of that class in a single array. :)
精彩评论