-1

here is my code:

+ (instancetype)sharedInstance
{
    static PanoramaDataManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[PanoramaDataManager alloc] init];
        [NSURLConnection sendAsynchronousRequest:[sharedInstance requestToService:kPanoramaAPIGetToken withParams:@{@"login" : kPanoramaAPILogin, @"password" : kPanoramaAPIPassword}] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (!connectionError) {
                NSError *error;
                NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data
                                                                             options:kNilOptions
                                                                               error:&error];
                if (!error) {
                    sharedInstance.token = [jsonResponse objectForKey:@"token"];
                } else {
                    [BxAlertView showError:error.description];
                }
            } else {
                [BxAlertView showError:connectionError.description];
            }
        }];
    });
    return [sharedInstance autorelease];
}

All i want to do is just to send the request to the server to receive the token for all the rest requests during the singleton initialisation. But I have an exception of bad access in the line where I try to set the property. If I try to write NSError *error = nil; the app is stopped with the exception of bad access. Any help?

ShurupuS
  • 2,923
  • 2
  • 24
  • 44

1 Answers1

2

remove the autorelease at the return;

If you release a static var you lose the value that you address with the pointer.

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
tdelepine
  • 1,986
  • 1
  • 13
  • 19