NSArray vs NSDictionary look up(NSArray vs NSDictionary 查找)
问题描述
检查一个对象是否已经存在于一个列表中更快更便宜.通过使用 NSArray contains 对象或检查 NSDictionary 的键是否已存在?
Which is quicker and less expensive for checking if an object already exists within a list. By using the NSArray contains object or by checking if a key already exists for an NSDictionary?
NSArray containsObject 选择器是否也遍历整个数组元素?另外检查一个键是否已经存在于字典中呢?这是否需要遍历所有键.
Also does the NSArray containObject selecter iterate through the whole array elements? Also what about checking if a key already exists within a dictionary? Does that require iterating through all the keys.
最后,检查一个对象是否已经存在于(同一类的)大对象列表中的最好和最快的方法是什么.
Finally, what is the best and quickest way to check if an object already exists within a large list of objects (of the same class).
提前致谢
推荐答案
你说的是多少个值?速度上的差异可能无关紧要,因此使选择成为代码中最有意义的选择.事实上,这可能应该是第一要务,除非并且直到您知道存在速度问题.
How many values are you talking about? The difference in speed may be irrelevant, thus making the choice be the one that makes the most sense in the code. In fact, that should probably be the first priority, unless and until you know that there is a speed problem.
短版:使用 NSDictionary,除非您有特殊需要.
Short version: Use NSDictionary unless you have a specific need not to.
这篇关于NSArray vs NSDictionary 查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:NSArray vs NSDictionary 查找
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01