【问题标题】:ARC forbids explicit message send 'retain' [duplicate]ARC 禁止显式消息发送“保留”[重复]
【发布时间】:2013-10-31 03:42:59
【问题描述】:

当我遇到问题时,我正在构建 ios 应用程序。它说 ARC 禁止显式消息发送“保留”。这是给我错误的代码。

    filePath= [[NSString stringWithFormat:@"%@", [[NSBundle mainBundle] resourcePath]] retain];

我应该在这里做什么?我的 ARC 已开启,我希望它保持开启,我该怎么办。

【问题讨论】:

  • 你了解什么是ARC吗?
  • 也被否决了,因为相关问题中有多个链接已经回答了这个问题。
  • 我不明白 arc 这就是我问的原因。我是 ios 的新手。

标签: ios automatic-ref-counting


【解决方案1】:
filePath = [NSString stringWithFormat:@"%@", 
           [[NSBundle mainBundle] resourcePath]];

【讨论】:

    【解决方案2】:

    只要去掉retain,编译器就会自动保证内存管理正确:

    filePath = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] resourcePath]];
    

    【讨论】:

      猜你喜欢
      • 2013-03-11
      • 2016-12-13
      • 2012-08-06
      • 2014-09-04
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多