int main(int argc, const char * argv[]) { @autoreleasepool {
//Create array of strings and a container for "devowelized" strings.
NSArray *originalStrings = @[@"Sauerkraut", @"Raygun", @"Big Nerd Ranch", @"Mississippi"];
NSLog(@"original strings: %@", originalStrings);
NSMutableArray *devowelizedStrings = [NSMutableArray array];
//Create a list of characters to be removed from the string.
NSArray *vowels = @[@"a", @"e", @"i", @"o", @"u"];
//Declare the block variable.
ArrayEnumerationBlock devowelizer;
//Compose a block and assign it to the variable.
devowelizer = ^(id string, NSUInteger i, BOOL *stop)
{
NSRange yRange = [string rangeOfString:@"y" options:NSCaseInsensitiveSearch];
//Did I find a "y"?
if (yRange.location != NSNotFound) {
*stop = YES; //will prevent further iterations
return;
}
NSMutableString *newString = [NSMutableString stringWithString:string];
//Iterate over the array of vowels, replacing occurances 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];
}
[devowelizedStrings addObject: newString];
};
//Iterate over the array with your block
[originalStrings enumerateObjectsUsingBlock:devowelizer];
NSLog(@"devowelized strings: %@", devowelizedStrings);
}
return 0;
}
[/code]
I get an error “Incompatible block pointer types assigning to ‘__strong ArrayEnumerationBlock’ (aka ‘void (^__strong)(__strong id, NSInteger, BOOL *)’) from ‘void (^)(__strong id, NSUInteger, BOOL *)’” Is this an iOS 8 thing?