什么是 NSCFDictionary? [英] What is an NSCFDictionary?

查看:14
本文介绍了什么是 NSCFDictionary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了一个 NSCFDictionary,但我不知道如何使用它.我知道它是 NSCFDictionary 类型,因为我打印了这个类,它以 __NCFDictionary 的形式出现.我不知道如何用它做任何事情.

I'm getting an NSCFDictionary returned to me and I can't figure out how to use it. I know it's of type NSCFDictionary because I printed the class and it came out as __NCSFDictionary. I can't figure out how to do anything with it.

我现在只是想坚持下去,但我什至无法让它发挥作用:

I'm just trying to hold onto it for now but can't even get that to work:

  NSDictionary *dict = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
  for(NSURLProtectionSpace key in [dict keyEnumerator])
  {
         NSCFDictionary *value = [dict objectForKey:key];
  }

allCredentials 的类引用说它应该返回一个字典,其值也是字典.我的赋值语句不起作用.我需要某种类型的演员吗?

The class reference for allCredentials says its supposed to return a dictionary whose values are also dictionaries. My assignment statement isn't working though. Do I need a cast of some kind?

推荐答案

NSDictionary 和其他 集合类实际上是类群:几个具体的子类 伪装在单个类的接口下的类:它们都提供相同的功能(因为它们是同一类的子类——在 NSDictionary 的情况下,这涉及三个原始方法"-count-objectForKey:-keyEnumerator),但有不同的内部工作方式,以在不同情况下高效,基于它们的方式重新创建以及它们可能存储的数据类型.

NSDictionary and the other collection classes are actually class clusters: several concrete subclasses classes masquerading under the interface of a single class: they all provide the same functionality (because they are subclasses of the same class — in NSDictionary's case, this involves the three "primitive methods" -count, -objectForKey:, and -keyEnumerator), but have different internal workings to be efficient in different situations, based on how they're created and what type of data they may be storing.

NSCFDictionary 只是 NSDictionary 的一个具体子类. 也就是说,您的 NSDictionaries 实际上可能是 NSCFDictionary 实例,但您应该将它们视为 NSDictionary 的实例,因为这将为您提供所需的字典-存储功能.

NSCFDictionary is simply a concrete subclass of NSDictionary. That is, your NSDictionaries may actually be NSCFDictionary instances, but you should treat them as instances of NSDictionary, because that will provide you with the required dictionary-storage functionality.

NSDictionary *value = [dict objectForKey:key];

<小时>

现在,您的代码不起作用的另一个原因是:NSURLProtectionSpace 是一个类,因此您应该将其用作指针,如下所示:


Now, another reason your code doesn't work: NSURLProtectionSpace is a class, so you should use it as a pointer, like this:

for (NSURLProtectionSpace *key ...

这篇关于什么是 NSCFDictionary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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