(After trying your code)
Okay, I see 2 possible reasons for you to say it does not work as you "planned".
First, since you compare case insensitive, most of the names are shown twice -- once with initial uppercase, once all lowercase.
Second, you always get a final line "The words and matches", with empty text in both places.
1. It's up to you to treat this as an error or "by design". Since you *are* comparing case insensitive, the exact same name *may* occur more than once in the word list.
If you want to only find exact unique same words, compare case sensitive instead.
You should also consider the case where the word list does contain duplicates! The supplied word list does not (at least, I don't expect it to), but then again you might want to re-use this code in a real world situation where it does. Again, it's up to you to decide whether the correct answer is
TRUE, this name occurs at least once in the word list
FALSE, this name does not appear once in the word list
(and it depends on your application which one you should choose).
2. This is by design and as expected. The command 'componentsSeparatedByString' splits your input on returns regardless of whether there is something 'left' and 'right' of it. A blank line inside the word list, for example, would get treated like this:
"abc\n\ndef\ngh" -> ["abc", "", "def", "gh"]
Now where does this last entry come from? Both lists end with a return, so the last entries look like this:
"..\nZyzomys\nZyzzogeton\n" (END)
and after splitting, this becomes "..", "Zyzomys", "Zyzzogeton", "" -- note the last entry "after" the final hard return.
You can solve this in two ways: cleaning up the lists right after reading (e.g., removing blank lines, including the last one), or simply ignore names and words with a length less than 1, using this line before comparing a name n against your word list:
if ([n length] < 1) continue;
Sort the words list and look in to binary searching. You will not be surprised by the speed increase, you will be *astonished*.
I tried this as well, and yes: the speed increase is marvellous. If you are interested, look into "indexOfObject". (As a side result, this also solves the Duplicate Words problem because it will always answer the question "is this name at least once in the words list".)