存档中的RestKit RKAttributeMapping fromKeyPath错误

时间:2016-03-29 21:16:09

标签: ios swift restkit restkit-0.20

我在混合的Swift / Obj C项目中使用RestKit 0.26.0。我们在Swift文件中设置关系映射,当我正常运行或构建项目时,一切正常。

但是,当我尝试将应用程序归档以便上传以进行分发时,由于在RKAttributeMapping和RKRelationshipMapping上使用了属性事件触发器:toKeyPath:withMapping方法的问题,归档失败。

具体来说,当我存档时,我收到此错误:

'(fromKeyPath: String!, toKeyPath: String!) -> RKAttributeMapping' is not convertible to '(fromKeyPath: String!, toKeyPath: String!) -> RKAttributeMapping!'

这段代码:

let errorMapping = RKObjectMapping(forClass: RKErrorMessage.self)
        errorMapping.addPropertyMapping(RKAttributeMapping(fromKeyPath: nil, toKeyPath: "userInfo"));

每当我在其他地方使用attributeMappingFromKeyPath:toKeyPath方法时,我得到相同/非常类似的错误:

mapping.addPropertyMapping(RKRelationshipMapping(fromKeyPath: "(userId).friends", toKeyPath: "friends", withMapping: friendsMapping))

产生此错误:

'(fromKeyPath: String!, toKeyPath: String!, withMapping: RKMapping!) -> RKRelationshipMapping' is not convertible to '(fromKeyPath: String!, toKeyPath: String!, withMapping: RKMapping!) -> RKRelationshipMapping!'

同样,应用程序在模拟器中构建并运行完全正常,不会出现任何错误或警告。它只是在存档期间出现问题。我已经尝试了所有简单的“常识”解决方案,例如清理构建文件夹,删除派生数据等。我已经在多台计算机上尝试过它们,所有这些都做同样的事情。

编辑:刚刚意识到Archive构建使用了与我的开发构建不同的构建配置,当我将运行应用程序的构建配置更改为Archive中使用的构建配置时,我得到相同的错误,因此只需更改一些内容在导致问题的构建配置中。

2 个答案:

答案 0 :(得分:2)

我通过将Swift编译器优化级别从快速,整个模块设置为快速来修复此问题。此设置位于您的构建设置中。

答案 1 :(得分:2)

我也遇到过这种情况,swift优化不允许将nil作为fromKeyPath传递给它的字符串!默认情况下为nonull。 RKAttributeMapping.h需要将params设置为可为空的,如下所示: +(instancetype)attributeMappingFromKeyPath :(可为空的NSString *)sourceKeyPath toKeyPath :(可为空的NSString *)destinationKeyPath;

更改优化级别也为我解决了问题,如果我找到更好的解决方案,我会回复