Trying to export NSTextView data to an RTF doc. My old code, mainly “filename” from NSSavePanel is depreciated. The docs state “use URL”. How can I do this?
Thanks.
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"rtf"]];
if ([panel runModal] == NSOKButton){
[[textView RTFFromRange:
NSMakeRange(0, [[textView string] length])]
writeToFile:[panel filename] atomically:YES];
}
As the doc says, you should use the
URLmethod ofNSSavePanel.The code will look the same, but you’ll use the
NSStringwriteToURL:atomically:encoding:error:method instead :Note the two parameters to specify an encoding (here I set UTF-8), and an error object. I give
NULLhere, but you would perhaps give a valid object to get error information.