Clarification of relatively weak links and save cycles

I have the following code:

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest: request]; operation.completionBlock = ^{ if([operation hasAcceptableStatusCode]){ } }; 

ARC does not seem to like [the hasAcceptableStatusCode operation], and I get the following warning: "Strong capture operation" in this block is likely to lead to a save loop. "

I'm not very good at abstracting, any idea how to go here?

Thanks,
Shay

+4
source share
1 answer

Blocks the capture (storage) of objects that you reference from the outside.

the completion of the block that will save the operation will be saved, hence the save cycle.

The best thing to do is create a weak link to the object and pass this instead

 AFHTTPRequestOperation * __weak theOperation = operation operation.completionBlock = ^{ if (theOperation) { return; } }; 

Weak links are safe at runtime, so if the operation was canceled, you just send the message to zero.

+6
source

Source: https://habr.com/ru/post/1382157/


All Articles