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

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

问题描述

我得到一个NSCFDictionary返回给我,我不知道如何使用它。我知道它的类型NSCFDictionary,因为我打印类,它出来作为__NCSFDictionary。我不知道如何做任何事情。

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.

我只是想抓住它现在,但甚至不能让它工作: / p>

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是一个类,所以你应该使用它作为一个指针,如this:


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天全站免登陆