Challenge 2 - (?)


This is my solution, could someone please let me know if I got it right - I got lots of duplications in the result so I am no longer sure if I got it right :frowning:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])

    @autoreleasepool {
        //read in the files
        NSString *nameString 
        = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" encoding:NSUTF8StringEncoding error:NULL];
        NSString *wordsString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" encoding:NSUTF8StringEncoding error:NULL];
        //Breaking the 2 files into 2 arrays of strings
        NSArray *names = [nameString componentsSeparatedByString:@"\n"];
        NSArray *words = [wordsString componentsSeparatedByString:@"\n"];
        //nested loop
        for (NSString *n in names) 
           for(NSString *w in words)
               if ([n caseInsensitiveCompare:w] == NSOrderedSame) {
                   NSLog(@"Found %@ and %@ are equal", n, w);
    return 0;


You got it right, the word files were updated since the book was written and the duplicates are expected as a result. Check the other thread on this solution to see some tricks for dealing with it.