Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 294
JPC Avatar asked Aug 23 '11 05:08

JPC


2 Answers

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 ...
like image 62
jtbandes Avatar answered Nov 07 '22 16:11

jtbandes


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.

like image 37
Chuck Avatar answered Nov 07 '22 15:11

Chuck