RestKit/RestKit — Issue #448: Crash with ARC Enabled
Author: blakewatters
Created: 2011-11-28 14:08:24+00:00
State: open

```
I don't know if this is how I'm supposed to use RestKit but I found
another way to create a EXC_BAD_ACCESS error on [self
fireAsynchronousRequest]. I need to make a call that does not map to
an object. Since we need to pass a delegate for every call, I created
a delegate callback class that I could use so that I didn't have to
pass self for the delegate and create a new class for every call.

Here is the callback class:

@implementation RestKitResponseDelegate

id _object;
SEL _successSelector;
SEL _failureSelector;

- (id)initWithCallback: (id)object success:(SEL)successSelector
failure:(SEL)failureSelector
{
self = [super init];
if (self) {
_object = object;
_successSelector = successSelector;
_failureSelector = failureSelector;
}
return self;
}

- (void)request:(RKRequest*)request didLoadResponse:
(RKResponse*)response {

if(![response isOK])
{
[_object performSelector:_failureSelector
withObject:response];
} else
{
[_object performSelector:_successSelector
withObject:response];
}

}
@end

Here's the call:

[loginService primeSession:self
selector:@selector(loginToApplication:)];

Here is the service method:

-(void) primeSession:(id)object selector:(SEL)successSelector
{
RestKitResponseDelegate* delegate = [[RestKitResponseDelegate
alloc] initWithCallback:object success:successSelector
failure:successSelector];
[[RKClient sharedClient] get:@"app?service=home"
delegate:delegate];
}

When I call the primeSession method I receive a EXC_BAD_ACCESS error
on [self fireAsynchronousRequest]. I assume this is because ARC or
RestKit is deallocating the delegate prematurely? Is there another way
to do this other than passing self as the delegate?
```