I have a C array of blocks defined like this:
void (^block1)() = ^void() {
doSomething1();
doSomething2();
};
void (^block2)() = ^void() {
doSomething3();
doSomething4();
};
// etc.
typedef void (^myBlockType)();
myBlockType arrayBlock[2];
arrayBlock[0] = block1;
arrayBlock[1] = block2;
but then I am trying to access that C array from inside a block, something like
void (^adjust)(int value) = ^void(int value) {
myBlockType myBlock = arrayBlock[value];
};
and Xcode is whining with
Cannot refer to declaration with an array type inside block
If this was an array of stuff like floats, integers, etc., there is this solution but how to do that for a C array of blocks?
Can I do
myBlockType array = calloc(2, sizeof(myBlockType));
? Is this the correct approach? In that case how do I initialize the values?