第二个NSLog消息将不会打印

时间:2012-07-14 02:29:42

标签: objective-c

由于某种原因,我无法将第二个NSLog消息输出到控制台。已经找了问题,但找不到它。提前谢谢。

#import <Foundation/Foundation.h>

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

  @autoreleasepool {

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

    // Create a list of characters that we'll 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 occurences of each with 
      // an empty string
      for (NSString *s in vowels) {
        NSRange fullRange = NSMakeRange(0, [newString length]);
                             [newString replaceOccurrencesOfString:s 
                                                        withString:@"" 
                                                           options:NSCaseInsensitiveSearch 
                                                             range:fullRange];
                             [newStrings addObject:newString];
                             }; //End of block assignment

      // Iterate over the array with our block
      [oldStrings enumerateObjectsUsingBlock:devowelizer];
      NSLog(@"new strings: %@", newStrings);

  };
    return 0;
}
}

3 个答案:

答案 0 :(得分:2)

您永远不会调用devowelizer块。因此,第二个NSLog永远不会执行。

答案 1 :(得分:1)

您创建了一个块并将其分配给devowelizer。看起来你已经把你的调用块放在块中了,这将无效。

答案 2 :(得分:0)

NSLog(@"new strings: %@", newStrings);

此行也在块内工作。您没有将块 devowelizer 称为无效的块。