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.
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)() = ^() {
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With