【问题标题】:RestKit and Swift bug response descriptorsRestKit 和 Swift 错误响应描述符
【发布时间】:2015-10-29 14:55:23
【问题描述】:

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

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;
}

BB用户

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

【问题讨论】:

    标签: ios objective-c swift mapping restkit


    【解决方案1】:

    在objective-c 中你应该看到完全相同的行为,因为pathPattern: "v1.2/user/wakeup"pathPattern: "v1.2/user/:userId" 就模式匹配器而言是相同的。所以,无论哪个先注册,都会先被使用。

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

    【讨论】:

    • 是的,在客观 C 中同样的行为 :( 并且 RestKit 团队认为这不是 RestKit 错误
    • 这不是 RestKit 错误 - 物理上不可能区分具有相同格式的两种模式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多