最新消息:20210917 已从crifan.com换到crifan.org

【已解决】iOS编程过程中出错:’autorelease’ is unavailable: not available in automatic reference counting mode, ARC forbids explicit message send of ‘autorelease’

iOS crifan 4342浏览 0评论

【问题】

给Your Second iOS App的BirdWatching中,添加自定义日期过程中,参考别处代码,拷贝过来一段代码:

self.dateFormatter = [[[NSDateFormatter alloc] init] autorelease];

结果出现错误:

autorelease is unavilable not available in automatic reference counting mode

 

【解决过程】

1.其实错误很明显,就是说,autorelease不能使用,原因在于我们之前创建当前iOS程序的时候,选择了“Use Automatic Reference Counting”,即使用了ARC,自动引用计数,所以此处,在写代码的时候,就不允许你再手动添加autorelease这个关键字了。

对应的,编译器会帮你自己优化生成对应的释放内存的操作。

所以,解决办法很简单,那就是直接删除autorelease这个关键字,变成:

self.dateFormatter = [[NSDateFormatter alloc] init];

即可。

 

【总结】

在创建iOS项目时,如果选择了"Use Automatic Reference Counting",那么代码中,自然就不需要再写autorelease了。

转载请注明:在路上 » 【已解决】iOS编程过程中出错:’autorelease’ is unavailable: not available in automatic reference counting mode, ARC forbids explicit message send of ‘autorelease’

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.212 seconds, using 23.35MB memory