简体   繁体   English

在字典中存储一组参数

[英]Storing a set of parameters in a dictionary

I have a networking method that provides a friendly interface to my API. 我有一种联网方法,可以为我的API提供友好的界面。 Something like: 就像是:

    getWeatherForCities:(NSArray *)cityCodes 
              startDate:(NSDate *)startDate
                endDate:(NSDate *)endDate 
             useCelcius:(BOOL)useCelcius
             maxResults:(NSNumber *)maxResults

This is called multiple times in my app, sometimes concurrently with different parameters. 在我的应用中,这被多次调用,有时并发使用不同的参数。 There is also a completion and failure block but they aren't needed here. 还有一个完成和失败块,但此处不需要它们。

I would like to add an option that tells the method only to execute the completion block if the data is different to the last time it was requested with the same parameters. 我想添加一个选项,该选项告诉方法仅在数据与上次使用相同参数请求数据不同时才执行完成块。 This way some consumers can say that they want to know everything, and others can ask only for data if it is new. 这样,一些消费者可以说他们想知道一切,而其他消费者则只能要求提供新数据。

It seems like I need some way to store a representation of all the parameters, alongside the last received response for those parameters. 似乎我需要某种方式来存储所有参数的表示形式以及这些参数最后收到的响应。 I would love to do this in an NSDictionary, but am open to other ideas. 我很乐意在NSDictionary中做到这一点,但愿意接受其他想法。 Is there some way to convert the parameters into a unique key? 有什么方法可以将参数转换为唯一键? Or some better solution? 还是一些更好的解决方案?

我目前正在使用[dictionary description]作为关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM