1

I have a simple application with 4 NSTextView element. I would like to be able to write a content of these views into a single file. What I am doing write know I am getting the NSData out of each of the elements using: dataFromRange, then I concatenate the data and write to a file.

There is however a problem. Each set of NSData I get contains a full file structure; e.g. if I use NSHTMLTextDocumentType in dataFromRange, in the output file I am getting four HTML files from to .

How can I avoid that? Is there a common solution for different file types.

4

1 回答 1

0

Prompted by Anoop Vaidya's answer I found solution. What I am doing is: -for my need I need to start with extra text, here "HEADER"

[data [[NSAttributedString alloc] initWithString:@"HEADER"]] mutableCopy];

-next I append the NSAttributedText from each NSTextView like that

[data insertAttributedString:[textView1 textStorage] atIndex:[data length]];

-finally, I write the combined text to a file using format of choice

[[data dataFromRange:range documentAttributes:dict error:error] writeToFile:path atomically:true];
于 2013-03-31T11:25:02.770 回答