Zugriff C Array innerhalb von Blöcken (variable Array-Anzahl) Objective-C

Blöcke sind in Ordnung, aber was über das schreiben von C-arrays?

Gegeben diese vereinfachte situation:

CGPoint points[10];
[myArray forEachElementWithBlock:^(int idx) {
    points[idx] = CGPointMake(10, 20); //error here
    //Cannot refer to declaration with an array type inside block
}];

Suche nach einer Weile fand diese mögliche Lösung, um es in ein struct:

__block struct {
    CGPoint points[100];
} pointStruct;

[myArray forEachElementWithBlock:^(int idx) {
    pointStruct.points[idx] = CGPointMake(10, 20);
}];

dieser funktionieren würde, aber es gibt eine kleine Einschränkung muss ich schaffen, das c-array dynamisch:

int count = [str countOccurencesOfString:@";"];
__block struct {
    CGPoint points[count]; //error here
    //Fields must have a constant size: 'variable length array in structure' extension will never be supported
} pointStruct;

Wie kann ich meinen CGPoint array innerhalb einer block?

ODER

Ist es auch überhaupt möglich, oder muss ich umschreiben, dass die block-Methode, um die volle Funktionalität?

InformationsquelleAutor der Frage | 2011-03-28

Schreibe einen Kommentar