我在 Swift/Obj C 混合项目中使用 RestKit 0.26.0。我们在 Swift 文件中设置关系映射,当我正常运行或构建项目时,一切正常。
但是,当我尝试将应用存档以上传分发时,由于 RKAttributeMapping 和 RKRelationshipMapping 上的 attributeMappingFromKeyPath:toKeyPath:withMapping 方法存在问题,存档失败。
具体来说,当我归档时,我得到这个错误:
'(fromKeyPath: String!, toKeyPath: String!) -> RKAttributeMapping' 不能转换为 '(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 中使用的构建配置时,我得到了同样的错误,所以只是做了一些改变在导致问题的构建配置中。
最佳答案
我通过将 Swift 编译器优化级别从 Fast, Whole Module 设置为 Fast 来解决这个问题。此设置位于您的build设置中。
关于ios - RestKit RKAttributeMapping fromKeyPath 存档错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36295227/