How to convert CFStringRef to NSString?

前端 未结 8 1918
借酒劲吻你
借酒劲吻你 2020-12-07 08:37
NSString *aNSString;
CFStringRef aCFString;
aCFString = CFStringCreateWithCString(NULL, [aNSString UTF8String], NSUTF8StringEncoding);
aCFString = CFXMLCreateStringB         


        
8条回答
  •  星月不相逢
    2020-12-07 08:39

    I'll add that not only can you go from CFString to NSString with only a type-cast, but it works the other way as well. You can drop the CFStringCreateWithCString message, which is one fewer thing you need to release later. (CF uses Create where Cocoa uses alloc, so either way, you would have needed to release it.)

    The resulting code:

    NSString *escapedString;
    NSString *unescapedString = [(NSString *) CFXMLCreateStringByUnescapingEntities(NULL, (CFStringRef) escapedString, NULL) autorelease];
    

提交回复
热议问题