web-dev-qa-db-ja.com

エラー「自動解放」は使用できません:自動参照カウントモードでは使用できません

StigのJSONライブラリを使用してHTTPリクエストを作成し、JSONを解析しようとしています。このエラーが発生します '自動リリース'は利用できません:このコードを使用すると、自動参照カウントモードでは利用できません

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]; 

[〜#〜]更新[〜#〜]

興味のある人にとって、これは正しいコードです: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];
16
Sam Baumgarten

変化する

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

SBJSON *json4 = [SBJSON new];

これにより、自動参照カウントをそのままにしておくことができます。

21
Jezen Thomas

このエラーを取り除く方法は、プロジェクトのビルド設定に移動することです。自動参照カウントを検索します。見つけたら、値を「NO」に設定します

23
Sam Baumgarten