NSString instance reports its class as NSCFString

bloudermilk picture bloudermilk · Dec 26, 2008 · Viewed 14.1k times · Source

My objective here is really simple -- I'm trying to set an NSString to some test data, then return the class, which should be NSString. Here's my code:

NSString* stringer = [NSString stringWithFormat: @"Test"];
NSLog(@"%@", [stringer class]);

The log says that the class is NSCFString, not NSString. What's going on here?

Answer

mipadi picture mipadi · Dec 26, 2008

NSString is really a container class for different types of string objects. Generally an NSString constructor does return an object that is actually of type NSCFString, which is a thin wrapper around the Core Foundation CFString struct.