Wie kann man das "Einfangen 'block' stark in diesem block wird wahrscheinlich führen zu eine retain-Zyklus"

Arbeite ich an diesem code, die nicht einige längere asynchrone Betrieb auf dem Netz und wenn es fertig ist löst es ein Abschluss-block, wo einige test ausgeführt wird und wenn eine variable eine bestimmte Wert eine weitere langwierige operation sollte sofort beginnen:

-(void) performOperation
{

    void(^completionBlock) (id obj, NSError *err, NSURLRequest *request)= ^(id obj,NSError *err, NSURLRequest *request){


        int variable=0;

        //Do completion operation A
        //...
        //...

        //Do completion operation B                
        //Get the variable value

        if(variable>0){
            [self doLengthyAsynchronousOperationWithCompletionBlock: completionBlock];
        }

    };

//Perform the lenhgty operation with the above completionBlock
    [self doLengthyAsynchronousOperationWithCompletionBlock: completionBlock];

}

-(void) doLengthyAsynchronousOperationWithCompletionBlock: completionBlock
{
    //Do some lengthy asynchronous stuff
}

Mit diesem code bekomme ich diese Warnung vom compiler:

WARNING: Block pointer variable 'completionBlock' is uninitialized when caputerd by the block

Ich geändert:

void(^completionBlock) (id obj, NSError *err, NSURLRequest *request)= ^(id obj,NSError *err, NSURLRequest *request)

in:

__block void(^completionBlock) (id obj, NSError *err, NSURLRequest *request)= ^(id obj,NSError *err, NSURLRequest *request)

aber ich bekomme diese Warnung:

WARNING 2: Capturing 'completionBlock' strongly in this block is likely to lead to a retain cycle

Wie kann ich dieses Problem beheben?

Dank

Nicola

  • Haben Sie einen Blick auf dieses Antwort
InformationsquelleAutor Nicola Prada | 2013-03-26
Schreibe einen Kommentar