Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error 'autorelease' is unavailable: not available in automatic reference counting mode

I trying to make a HTTP request and parse JSON using Stig's JSON Library. I'm getting this error 'autorelease' is unavailable: not available in automatic reference counting mode when I use this code

NSURLRequest *request2;
request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://sandbox.CompanyName.com/api/%@/users/%@/user_badges?url=CompanyName.map2.com&amount=999999999999",[information stringForKey:@"apiKey"] , [information stringForKey:@"userID"]]]];

NSURLConnection *connection2;
connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES];
NSURLResponse *resp2;
NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp2 error:nil];
NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding];
NSLog(@"getUsersBadges called");
NSError *error4;
SBJSON *json4 = [[SBJSON new] autorelease];
// NSArray *luckyNumbers = [json objectWithString:responseString error:&error];
NSDictionary *luckyNumbers4 = [json4 objectWithString:cDataString2 error:&error4];

[cDataString2 release]; 

UPDATE

For anyone interested, this is the correct code: NSURLRequest *request2; request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://sandbox.CompanyName.com/api/%@/users/%@/user_badges?url=CompanyName.map2.com&amount=999999999999",[information stringForKey:@"apiKey"] , [information stringForKey:@"userID"]]]];

NSURLConnection *connection2;
connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES];
NSURLResponse *resp2;
NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp2 error:nil];
NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding];
NSLog(@"getUsersBadges called");
NSError *error4;
SBJSON *json4 = [SBJSON new];
// NSArray *luckyNumbers = [json objectWithString:responseString error:&error];
NSDictionary *luckyNumbers4 = [json4 objectWithString:cDataString2 error:&error4];
like image 722
Sam Baumgarten Avatar asked Jun 15 '11 19:06

Sam Baumgarten


2 Answers

The way that you get rid of this error is to go into your projects build settings. Search for automatic reference counting. Once you find it set the value to "NO"

like image 110
Sam Baumgarten Avatar answered Nov 01 '22 15:11

Sam Baumgarten


Change

SBJSON *json4 = [[SBJSON new] autorelease];

to

SBJSON *json4 = [SBJSON new];

This will allow you to leave automatic reference counting intact.

like image 32
Jezen Thomas Avatar answered Nov 01 '22 14:11

Jezen Thomas