【问题标题】:Xcode 'autorelease is unavailable in URL requestXcode 'autorelease 在 URL 请求中不可用
【发布时间】:2013-02-04 04:25:21
【问题描述】:

我的 .m 文件中有以下代码:

- (IBAction)LoginButton:(id)sender {

// create string contains url address for php file, the file name is phpFile.php, it receives parameter :name
NSString *strURL = [NSString stringWithFormat:@"http://www.myURL.com/verify.php?Email=%@",Email.text];

// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

// to receive the returend value
NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]autorelease];

NSLog(@"%@", strResult);

UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle:@"Result:"
                      message:strResult
                      delegate:nil
                      cancelButtonTitle:@"Okay"
                      otherButtonTitles:nil];    
                      [alert show]; 
}

我发现自动释放在自动引用计数模式下不可用。

下面这行似乎有问题:

NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]autorelease];

我该如何解决这个问题?

【问题讨论】:

    标签: xcode web-services autorelease


    【解决方案1】:

    只需删除autorelease 调用;如果您使用 ARC(自动引用计数),则无需担心内存管理。

    【讨论】:

      猜你喜欢
      • 2014-09-12
      • 2017-10-14
      • 2013-06-25
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 2018-04-11
      相关资源
      最近更新 更多