I am using RestKit 0.26.0 in a mixed Swift / Obj C project. We are setting up relationship mappings in a Swift file, and when I run or build the project normally, everything works correctly.
However, when I try to archive the app to upload for distribution, the archive fails due to problems with the attributeMappingFromKeyPath:toKeyPath:withMapping methods on RKAttributeMapping and RKRelationshipMapping.
Specifically, when I archive, I get this error:
'(fromKeyPath: String!, toKeyPath: String!) -> RKAttributeMapping' is not convertible to '(fromKeyPath: String!, toKeyPath: String!) -> RKAttributeMapping!'
for this block of code:
let errorMapping = RKObjectMapping(forClass: RKErrorMessage.self)
errorMapping.addPropertyMapping(RKAttributeMapping(fromKeyPath: nil, toKeyPath: "userInfo"));
I get the same/a very similar error whenever I use the attributeMappingFromKeyPath:toKeyPath method in other places as well:
mapping.addPropertyMapping(RKRelationshipMapping(fromKeyPath: "(userId).friends", toKeyPath: "friends", withMapping: friendsMapping))
yields this error:
'(fromKeyPath: String!, toKeyPath: String!, withMapping: RKMapping!) -> RKRelationshipMapping' is not convertible to '(fromKeyPath: String!, toKeyPath: String!, withMapping: RKMapping!) -> RKRelationshipMapping!'
Again, the app builds and runs in the simulator completely fine, with out raising any errors or warnings. Its just during the archive that the problem arises. I have tried all the simple 'common sense' solutions like cleaning the build folder, deleting derived data, etc. I've tried it on multiple computers and all of them do the same thing.
EDIT: Just realized that the Archive build uses a different build configuration than my development build, when I change the build configuration for running the app to the same used in Archive, I get the same error, so there is simply something changed in the build config that is causing the issue.
I fixed the issue by setting the Swift Compiler Optimization Level from Fast, Whole Module to just Fast. This setting is found in your build settings.