struct - Access C Array within blocks (variable array count) Objective-C -


The blocks are OK but what about writing C arrays?

Looking at this simple situation: CGPoint points [10]; [MyArray forEElementWithBlock: ^ (Int idx) {number [idx] = CG point make (10, 20); // error here can not mention declaration with an array type inside // block}};

After searching for some time, found this possible solution, put it in a straight:

  __ block straight {CGPoint points [100]; } Point streak; [MyArray forEElementWithBlock: ^ (Int IDX) {pointStruct.points [idx] = CGPEXMake (10, 20); }];   

This will work but there are some limitations that I need to dynamically create a C:

  int count = [str countOcurencesOfString: @ ";" ]; __blak straight {gg point number [count]; // Here there should be a static shape in the error // field: 'variable length array' structure in the structure will never be supported) pointStruct;   

How can I get my CGPoint array within a block ?

OR

Is it possible at all or do I have to type the block method again to get the full functionality?

Maybe you can allocate arrays on the heap?

  // allocates a simple array to the heap. In the array there will be [myArray count] items, each size to fit a CGPoint. CGPoint * digits = [myArray count], sif (CG point)); // Make sure that the allocation is completed successfully, you want to handle some more flawed error here. NSParameterAssert (points! = Null); // loop on myArray, whatever you want, [myArray forEElementWithBlock: ^ (int idx) {points [idx] = "A" | | | }]; // Memory taken by C array is free of charge. Of course you probably want to do something else with the // array, otherwise this does not mean much to the effect: // free (points), points = zero;    

Comments