NSString *aNSString; CFStringRef aCFString; aCFString = CFStringCreateWithCString(NULL, [aNSString UTF8String], NSUTF8StringEncoding); aCFString = CFXMLCreateStringByUnescapingEntities(NULL, aCFString, NULL);
How can I get a new NSString from aCFString?
NSString and CFStringRef are ‘Toll free bridged’, meaning that you can simply typecast between them.
For example:
works perfectly and transparently. Likewise:
The previous syntax was for MRC. If you’re using ARC, the new casting syntax is as follows:
works as well. The key thing to note is that CoreFoundation will often return objects with +1 reference counts, meaning that they need to be released (all CF[Type]Create format functions do this).
The nice thing is that in Cocoa you can safely use autorelease or release to free them up.