【问题标题】:Obj-C Error "Implicit Conversion of Int to Collection * is disallowed with ARCObj-C 错误“ARC 不允许将 Int 隐式转换为 Collection *
【发布时间】:2012-08-15 18:28:11
【问题描述】:
- (void)saveCollectionMoment:(NSArray *)collectionMoments
{
    for (NSDictionary *momentData in collectionMoments) {

        int mID = [[momentData objectForKey:@"mID"] intValue];

        FMDBDataAccess *db = [[FMDBDataAccess alloc] init];
        [db insertMoment:mID toCollection: cID];
    }
}

以上内容应该采用从 JSON 返回提供的 id 并使用 FMDB 使用 mID 和 cID 更新 SQLite 数据库表,但我得到的只是以下错误。

ARC 不允许将“int”隐式转换为“Moment *”

如有任何帮助,我们将不胜感激。

【问题讨论】:

  • 很明显insertMoment:toCollection: 方法不期望得到int 作为第一个参数,而是期望类Moment 的实例

标签: objective-c ios5 int automatic-ref-counting fmdb


【解决方案1】:

问题在于 insertMoment:toCollection: 期望 Moment* 对象作为其第一个参数,而您却尝试向其传递整数 ID。

您应该更改您的代码,让insertMoment:toCollection: 接受整数MomentID 作为其第一个参数,或者在调用insertMoment:toCollection: 方法之前通过其MomentID 获取Moment*

【讨论】:

  • 谢谢你,我去看看,当你说 Moment* 时,你的意思是我需要在这里使用指针吗?
  • @JustinErswell 我假设Moment 是一个Objective-C 对象,而Objective-C 对象总是通过指针访问。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-15
  • 1970-01-01
  • 2012-03-30
相关资源
最近更新 更多