Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

AFHTTPRequestOperation - hasAcceptableStatusCode in completionBlock #137

kazzar opened this Issue Dec 1, 2011 · 1 comment


None yet
2 participants

kazzar commented Dec 1, 2011

Hi all
i have a little problem with AFHTTPRequestOperation with arc.
I use snipped found in project page, and i have a warning here:

AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
operation.completionBlock = ^ {
    if ([operation hasAcceptableStatusCode]) { *// Warning here
        NSLog(@"Friend Request Sent");
    } else {
        NSLog(@"[Error]: (%@ %@) %@", [operation.request HTTPMethod], [[operation.request URL] relativePath], operation.error);

the warning says: "Capturing ''operation' strongly in this block is likely to lead to a retain cycle"

sorry for my bad english
thx for great work!


mattt commented Dec 1, 2011

Hi Dario,

There's a question on Stack Overflow that answers this really well, so please look at that.

As an alternative suggestion, if you do setCompletionBlockWithSuccess:failure: checks for hasAcceptableStatusCode and hasAcceptableContentType will automatically be done for you. So instead, it would be:

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Friend Request Sent");
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"[Error]: (%@ %@) %@", [operation.request HTTPMethod], [[operation.request URL] relativePath], operation.error);

I'll consider updating that snippet in the README...

@mattt mattt closed this Dec 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment