关于 RestKit 中的对象序列 [英] About the object sequence in the RestKit

查看:33
本文介绍了关于 RestKit 中的对象序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用 RestKit 来处理我的网络请求事务.有一种使用排序描述符进行排序的解决方案.但是服务器发送的数据没有排序键.

I recently used RestKit to handle my net request affairs. There is a solution for the sort with the sort descriptor. But there is no sort key for the data sent by the server.

如何让数据与服务器保持相同的顺序.

How can I keep the data in the same sequence as the server.

有一个解决方案,我可以在对象中添加一个sortID,但这不是很优雅.我想知道RestKit中有没有针对这个问题的api?

There is a solution that I can add a sortID in the object, but this is not very elegant. I want to know if there is any api in RestKit for this problem?

推荐答案

您应该将 sortID 添加到对象 - 这是合适的解决方案.要使用您需要使用映射可用的 @metadata 的值填充它:

You should add sortID to the object - this is the appropriate solution. To populate it with a value you need to use the @metadata made available to your mappings:

@"@metadata.mapping.collectionIndex" : @"sortID"

此代码假定您使用字典 (addAttributeMappingsFromDictionary:) 指定映射.

This code assumes that you are specifying your mapping with a dictionary (addAttributeMappingsFromDictionary:).

记录此处collectionIndex为您提供一个 NSNumber 表示响应数据中项目的顺序.

Documented here, the collectionIndex provides you with an NSNumber representing the order of the item in the response data.

这篇关于关于 RestKit 中的对象序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆