I have been struggeling with this issue for a while since i don't think i fully understand the retain cycles. I am totally new to this and i'm trying to learn more about it.
I am getting the EXC_BAD_ACCESS message with the following code.
I started using the weakSelf because i get 2 warnings about the retain cycle if i just use self.successBLock();. The exact warning is:
Capturing 'self' strongly in this block is likely to lead to a retain cycle
Maybe i shouldn't even bother using the weak but i am no so sure about this.
This is the part where i use the weakSelf in a block:
__weak Request *weakSelf = self;
[_operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
weakSelf.successBlock(operation.response, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
weakSelf.failureBlock(operation.response, error);
}];
This is how i assign the block properties:
typedef void (^successBlock)(NSHTTPURLResponse *response, id responseObject);
typedef void (^failureBlock)(NSHTTPURLResponse *response, NSError *error);
@property (nonatomic, copy) successBlock successBlock;
@property (nonatomic, copy) failureBlock failureBlock;