问题
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.
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?
回答1:
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"
This code assumes that you are specifying your mapping with a dictionary (addAttributeMappingsFromDictionary:
).
Documented here, the collectionIndex
provides you with an NSNumber
representing the order of the item in the response data.
来源:https://stackoverflow.com/questions/20237615/about-the-object-sequence-in-the-restkit