我有一堆循环可以在 plist 中为我找到正确的单词并将它们过滤掉。但是,它太慢了,plist 中总共有大约 2000 个单词。请参阅下面的代码,我需要加快速度,它会导致大约 2-3 秒的延迟!不知道我怎么能。
plist 由大约 200 个数组组成,每个数组有 10 个单词。所以我拿了 plist 的字典,dict
. 然后遍历所有这些数组,直到找到我需要的单词。
for (int i = 0; i < [lang1Words count]; i++)
{
NSString *errorWordLang1 = [lang1Words objectAtIndex:i];
for (NSArray *a in [dict allValues])
{
for (NSString *s in a)
{
if ([errorWordLang1 isEqualToString:s])
{
NSArray *temp = [dict allKeysForObject:a];
NSString *originLang1ArrayKey = [temp objectAtIndex:0];
NSArray *lang1Temp = [self getWordsArrayForKey:originLang1ArrayKey];
NSInteger index = [lang1Temp indexOfObject:errorWordLang1];
NSString *originLang2ArrayKey;
if ([languageKey isEqualToString:@"Latin"]) originLang2ArrayKey = [originLang1ArrayKey stringByReplacingOccurrencesOfString:@"Latin" withString:@"English"];
else if ([languageKey isEqualToString:@"English"]) originLang2ArrayKey = [originLang1ArrayKey stringByReplacingOccurrencesOfString:@"English" withString:@"Latin"];
NSArray *lang2Temp = [self getWordsArrayForKey:originLang2ArrayKey];
NSString *errorWordLang2 = [lang2Temp objectAtIndex:index];
if (errorWordLang2 == nil || errorWordLang1 == nil) break;
[orderedLang2Words addObject:errorWordLang2];
[orderedLang1Words addObject:errorWordLang1];
}
}
}
}