JScarry
JScarry

Reputation: 1507

How can I pick a one array out of 400?

I have a file with 420 NSArrays of words. Each array has between 10 and 200 NSStrings. The file size is 988 KB.

It builds and runs fine when the compiler does no optimization. But when I try to make an archive it hangs at "Analyzing 86 of 86 files." I suspect it's because the compiler gets stuck on optimizing the file. I split the file into two parts and it will archive after about an hour of compiling.

I put the arrays into a dictionary and then return just the one array that I want. I think that's what's hanging up the compiler.

-- 420 NSArrays ...
NSArray *foils_easy = [NSArray arrayWithObjects:a_easy, about_easy, ... you_easy, your_easy, nil];

NSArray *keys = @[@"a", @"about", ... @"you", @"your"];

NSDictionary *allFoils = [NSDictionary dictionaryWithObjects:foils_easy forKeys:keys];
return [allFoils objectForKey:target];

I don't really need the dictionary, except to determine which array to return. Is there a way to construct the array name so that it can be returned? Maybe something like you can use in putting an image on the screen?

NSString *foregroundImageName = [NSString stringWithFormat:@"%@ForegroundL1", scene];

I really didn't want to put in 420 'if' statements so I'm hoping there's a better solution.

Upvotes: 0

Views: 90

Answers (1)

Ben Baron
Ben Baron

Reputation: 14815

You should try putting the word arrays into a plist file and loading it at runtime, rather than including all of these string literals. That will keep your code cleaner, and probably resolve this issue.

Upvotes: 5

Related Questions