Block Exercise Trouble



First off, I’m a complete newly to coding, so I apologize if I am missing something super simple. I am getting an error code: “Thread 1:EXC_BAD_ACCESS (code=2, address=0x7fff5f3fffe8” on the last NSLog line of the following code. I’m sure I am just missing some simple letter I typed wrong, but I am not finding it. Thanks for any help!

[code] // Create an array of strings to devowelize and a container for new ones
NSArray *oldStrings = [NSArray arrayWithObjects:@“Sauerkraut”, @“Raygun”, @“Big Nerd Ranch”, @“Missippippi”, nil];
NSLog(@“old strings: %@”, oldStrings);
NSMutableArray *newStrings = [NSMutableArray array];

    // Create a list of vowels we will remove from the string
    NSArray *vowels = [NSArray arrayWithObjects:@"a", @"e", @"i", @"o", @"u", nil];
    // Declare the block variable
    void (^devowelizer) (id, NSUInteger, BOOL *);
    // Assign a block to the variable
    devowelizer = ^(id string, NSUInteger i, BOOL *stop){
        NSMutableString *newString = [NSMutableString stringWithString:string];
        // Iterate over the array of vowels, replacing occurances of each
        // with an emplty string
        for (NSString *s in vowels) {
            NSRange fullRange = NSMakeRange(0, [newString length]);
            [newString replaceOccurrencesOfString:s
        [newStrings addObject:newStrings];
    }; // End of block assignment
    // Iterate over the array with our block
    [oldStrings enumerateObjectsUsingBlock:devowelizer];
    NSLog(@"new strings: %@", newStrings);



You have typed in one s too many.
As a result you are adding newStrings array to itself, which causes the NSArray’s description method to go into an endless loop.

            // [newStrings addObject:newStrings]; // It's here!
            [newStrings addObject:newString];
        // Iterate over the array with our block
        [oldStrings enumerateObjectsUsingBlock:devowelizer];
        NSLog (@"new strings: %@", newStrings);
    return 0;


Ha! Thank you! I figured it was something like that, but yesterday was a long day, and I just couldn’t see it…