From 91bfb6c9754840719af3b55ab3b6a7704c8eb535 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 17 Dec 2007 15:03:38 -0500 Subject: [PATCH] Adding some comments to the -[findWords:] method * Source/AppController.m --- Source/AppController.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/AppController.m b/Source/AppController.m index 04e257e..056c3fb 100644 --- a/Source/AppController.m +++ b/Source/AppController.m @@ -49,26 +49,31 @@ int tileCount = [tileString length]; NSMutableArray *tiles = [NSMutableArray arrayWithCapacity:tileCount - 1]; - for (int i = 0; i < tileCount; i++) { [tiles addObject:[tileString substringWithRange:NSMakeRange(i, 1)]]; } + // create character sets from the tiles NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:tileString]; NSCharacterSet *charsetInverted = [charset invertedSet]; + // iterate over the dictionary to build our word list for (NSString *word in dictionary) { + // word is larger than the number of tiles we have, remove if ([word length] > tileCount) { continue; } - if ([word rangeOfCharacterFromSet:charsetInverted].location == NSNotFound) + // if the word contains characters we don't have, then remove it + if ([word rangeOfCharacterFromSet:charsetInverted].location != NSNotFound) { - [wordlist addObject:[[Word alloc] initWithWord:word]]; + continue; } + + [wordlist addObject:[[Word alloc] initWithWord:word]]; } // resort -- 2.43.5