开发者

What is an NSCFDictionary?

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 th开发者_Go百科e 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];
  }

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 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 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];

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 is the private subclass of NSDictionary that implements the actual functionality. It's just an NSDictionary. Just about any NSDictionary you use will be an NSCFDictionary under the hood. It doesn't matter to you code. You can type the variable as NSDictionary and use it accordingly.


I have an NSCFDictionary that is actually a NSMutableDictionary object, I can delete items from it. I mention this to further clarify jtbandes' answer: the NSCFDictionary object may be any object that inherits from NSDictionary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜