gpt4 book ai didi

ios - RestKit 和 Swift 错误响应描述符

转载 作者:行者123 更新时间:2023-11-30 14:10:17 25 4
gpt4 key购买 nike

我添加了响应描述符作为函数的结果

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 中不会发生此错误。

为什么?

映射:

BB唤醒

class func mapping() -> RKObjectMapping {
var mapping : RKObjectMapping = RKObjectMapping(forClass: BBWakeUP.self);
mapping.addAttributeMappingsFromDictionary(["localization_hash" : "localizationHash"]);
return mapping;
}

BB用户

class func userMapping() -> RKEntityMapping {
var mapping = RKEntityMapping(forEntityForName: "BBUser", inManagedObjectStore: RKManagedObjectStore.defaultStore());
mapping.identificationAttributes = ["userId"];
mapping.addAttributeMappingsFromDictionary(["id" : "userId"]);
return mapping;
}

最佳答案

在 Objective-C 中,您应该看到完全相同的行为,因为 pathPattern: "v1.2/user/wakeup"pathPattern: "v1.2/user/:userId" 就模式匹配器而言是相同的。所以,先注册的就先使用。

如果您的 obj-c 正在工作,那么它的指定方式有所不同。

关于ios - RestKit 和 Swift 错误响应描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31856101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com