我有一个GET Web服务,我以两种不同的方式调用,一次是使用该Web服务的参数,一次是不使用参数。尽管两种情况下的响应结构都相同,但响应却不同。我想将结果映射到不同的表中,但是由于RestKit无法区分两者,所以我无法这样做,以下是在不使用任何查询参数的情况下调用Web服务时的响应描述符:
let advisorMapping = RKEntityMapping(forEntityForName: "Advisor", in: managedObjectStore)
advisorMapping?.identificationAttributes = ["id"]
advisorMapping?.addAttributeMappings(from: ["Id":"id","Name":"name","FirmName":"firmName"])
let advisorResponseDescriptor = RKResponseDescriptor(mapping: advisorMapping, method: .GET, pathPattern: "advisors", keyPath: nil, statusCodes:nil )
objectManager?.addResponseDescriptor(advisorResponseDescriptor)
当我使用查询参数调用相同的Web服务时,我会使用:
let advisorFilterMapping = RKEntityMapping(forEntityForName: "AdvisorFilter", in: managedObjectStore)
advisorFilterMapping?.identificationAttributes = ["id"]
advisorFilterMapping?.addAttributeMappings(from: ["Id":"id","Name":"name","FirmName":"firmName"])
let advisorFilterResponseDescriptor = RKResponseDescriptor(mapping:advisorFilterMapping, method: .GET, pathPattern: "advisors?", keyPath: nil, statusCodes:nil )
objectManager?.addResponseDescriptor(advisorFilterResponseDescriptor)
但是,RKResponseDescriptor
在以上两个映射中没有区别,我来自第二个Web服务的数据被插入到第一个表中。任何帮助将不胜感激。