我有作为函数
的结果添加了响应描述符class func responseDescriptors() -> [RKResponseDescriptor] {
var successCodes : NSIndexSet = RKStatusCodeIndexSetForClass(RKStatusCodeClass.Successful);
var retResponseDescriptors : [RKResponseDescriptor] = [];
//Settings
retResponseDescriptors.append(RKResponseDescriptor(mapping: BBLocalization.mapping(), method: RKRequestMethod.GET, pathPattern: BBServerAPIPaths.Settings.LanguageTranslate.rawValue, keyPath: nil, statusCodes: successCodes));
retResponseDescriptors.append(RKResponseDescriptor(mapping: BBWakeUP.mapping(), method: RKRequestMethod.GET, pathPattern: "v1.2/user/wakeup", keyPath: nil, statusCodes: successCodes));
//User
retResponseDescriptors.append(RKResponseDescriptor(mapping: BBUser.mapping(), method: RKRequestMethod.GET, pathPattern: "v1.2/user/:userId", keyPath: nil, statusCodes: successCodes));
return retResponseDescriptors;
}
通过电话添加
RKObjectManager.sharedManager().addResponseDescriptorsFromArray(self.responseDescriptors());
映射响应本地化工作很好,但如果我调用wakeUp它映射到
to object <BBUser: 0x7fbe306b1210>
如果我没有为用户请求添加响应描述符
//User
//retResponseDescriptors.append(RKResponseDescriptor(mapping: BBUser.mapping(), method: RKRequestMethod.GET, pathPattern: "v1.2/user/:userId", keyPath: nil, statusCodes: successCodes));
运作良好,映射到BBWake工作。
在ObjectiveC中,这种错误不会发生。
为什么?
映射:
BBWakeUP
class func mapping() -> RKObjectMapping {
var mapping : RKObjectMapping = RKObjectMapping(forClass: BBWakeUP.self);
mapping.addAttributeMappingsFromDictionary(["localization_hash" : "localizationHash"]);
return mapping;
}
BBUser
class func userMapping() -> RKEntityMapping {
var mapping = RKEntityMapping(forEntityForName: "BBUser", inManagedObjectStore: RKManagedObjectStore.defaultStore());
mapping.identificationAttributes = ["userId"];
mapping.addAttributeMappingsFromDictionary(["id" : "userId"]);
return mapping;
}
答案 0 :(得分:0)
在objective-c中,您应该看到完全相同的行为,因为pathPattern: "v1.2/user/wakeup"
和pathPattern: "v1.2/user/:userId"
在模式匹配器方面是相同的。因此,首先使用首先注册的那个。
如果你的obj-c正在运行,那么就会以不同的方式指定它。