Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Block pointer to non-function type is invalid"

Here I have a method to encode a string (it is incomplete), and you will find my problem is an error: "Block pointer to non-function type is invalid"

+ (NSString *)encodeString: (NSString *)string {
    __block int indexShift;
    __block NSString *dictionary = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    __block NSString *encodeDictionary = @"mahgbcjdfukripylswxovzetqnFMAJWGCQYXLOETPBKSVNIZUHDR";
    __block NSString *encodeString = @"";

    void (^encode) = ^{ // Error here, "Block pointer to non-function type is invalid"
        for (int x = 0; x < string.length; x++) {
            int index = [dictionary indexOf:[string characterAtIndex:x]];
            indexShift += index;
            encodeString = [encodeString stringByAppendingFormat:@"%c", [encodeDictionary characterAtIndex:index+indexShift]];
        }
    };

    return encodeString;
}

Please tell me why this is happening, or what I need to change to fix it.

like image 597
Wrsford Avatar asked Aug 09 '12 19:08

Wrsford


1 Answers

That's incorrect syntax for declaring an inline block. The general form is as follows:

ReturnType(^block_name)(parmeter, types, here) = ^(parameter, types, here) {

};

So you're looking for:

void(^encode)() = ^() {

};
like image 113
Matt Wilding Avatar answered Sep 17 '22 14:09

Matt Wilding