I have a C-array of blocks defined as follows:
void (^block1)() = ^void() {
doSomething1();
doSomething2();
};
void (^block2)() = ^void() {
doSomething3();
doSomething4();
};
typedef void (^myBlockType)();
myBlockType arrayBlock[2];
arrayBlock[0] = block1;
arrayBlock[1] = block2;
but then I try to access this C array from inside the block, something like
void (^adjust)(int value) = ^void(int value) {
myBlockType myBlock = arrayBlock[value];
};
and Xcode whines with
Cannot reference an ad with an array type inside a block
If it was an array of things like float, integers, etc., there is this solution , but how to do it for an array of C blocks?
Can i do
myBlockType array = calloc(2, sizeof(myBlockType));
? Is this the right approach? In this case, how to initialize the values?
source
share