Ich arbeite an diesem Code, der einige lange asynchrone Operation im Netz und wenn es fertig ist löst einen Abschlussblock, wo einiger Test ausgeführt wird, und wenn eine Variable einen bestimmten Wert wieder mit einer langwierigen Operation sofort starten bekommen soll:Wie zu beheben "Capturing 'Block' stark in diesem Block wird wahrscheinlich zu einem Retain-Zyklus führen"
-(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, den ich diese Warnung vom Compiler erhalten:
WARNING: Block pointer variable 'completionBlock' is uninitialized when caputerd by the block
I 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 habe diese andere 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
Werfen Sie einen Blick auf diese [Antwort] (http://stackoverflow.com/questions/7761074/arc-blocks-and-retain-cycles) –