Convert to Precomposed Unicode String using Python-AppKit-ObjectiveC

This document from Apple Technical Q & A QA1235 describes how to convert Unicode strings from compiled to decomposed version. Since I have a problem with file names containing some characters (like an accent grave), I would like to try the conversion function

void CFStringNormalize (CFMutableStringRef theString, CFStringNormalizationForm theForm);

I use this with Python and the AppKit library. If I pass the Python string as an argument, I get:

CoreFoundation.CFStringNormalize ("ABC", 0) 2009-04-27 21: 00: 54.314 Python [4519: 613] * - [OC_PythonString _cfNormalize:]: unrecognized selector sent to instance 0x1f02510 Traceback (last last call): File " ", line 1, in ValueError: NSInvalidArgumentException - * - [OC_PythonString _cfNormalize:]: unrecognized selector sent to instance 0x1f02510

I suppose this is because CFMutableStringRef is needed as an argument. How to convert Python string to CFMutableStringRef?

+3
source share
1 answer

OC_PythonString (which Python strings are attached to) is a subclass of NSString, so you can get NSMutableString with:

mutableString = NSMutableString.alloc().initWithString_("abc") 

then use mutableString as an argument to CFStringNormalize.

+1
source

All Articles