2011-08-01 14 views
0

私は読む必要のあるIOSのNSDataオブジェクトにRTFDデータを持っています。 MacOSXでは、NSAttributedStringを使ってそれらを読み取るだけでしたが、今はIOSでサポートされていないことが分かりました。IOSのRTFDデータを読む

attribString = [[NSAttributedString alloc] initWithRTFD:note documentAttributes:&dict]; 

IOSのRTFDデータのテキストだけを読み取る方法はありますか?

+0

initWithRTFD:documentAttributes:はサポートされていませんが、NSAttributedStringクラスはiOS 3.2以降でサポートされています。 – JustSid

+0

rtfを読み取るために使用できますか? –

答えて

0

iOSのrtfdは、ディレクトリのようなものです。テキスト部分のみを取得したい場合は、次を試してみてください:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"photo" ofType:@"rtfd"]; 
NSFileManager *fileManager = [NSFileManager defaultManager]; 
NSArray *content = [fileManager contentsOfDirectoryAtPath:filePath error:nil]; 
NSString *textFilePath = [filePath stringByAppendingPathComponent:@"TXT.rtf"];//you can get the path component from the content; usually it is TXT.rtf 
NSError *error = nil; 
NSString *pureText = [[NSString alloc] initWithContentsOfFile:textFilePath encoding:NSASCIIStringEncoding error:&error]; 
NSLog(@"pureText:\n%@",pureText); 

希望すると助かります。