-[NSMutableAttributedString initWithHTML:documentAttributes:]
特殊文字を台無しにしているようです:
NSString *html = @"“Hello” World"; // notice the smart quotes
NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding];
NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithHTML:htmlData documentAttributes:nil];
NSLog(@"%@", as);
“Hello†World
それはいくつかのRTFコマンドに続いて印刷されます。私のアプリケーションでは、属性付きの文字列を RTF に変換して で表示しましたNSTextView
が、そこでも文字が壊れています。
ドキュメントによると、デフォルトのエンコーディングは UTF-8 ですが、明示的にしようとしましたが、結果は同じです。
NSDictionary *attributes = @{NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]};
NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithHTML:htmlData documentAttributes:&attributes];