0

Im trying to implement a save feature to save an html file. Currently it returns errors when I try and save. My code is

- (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{
NSData *saveData = [[[editorView textStorage] string] dataUsingEncoding:NSUTF8StringEncoding];
[saveData writeToURL:absoluteURL ofType:typeName error:outError];

if ( outError != NULL ) {
    *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
else {
    return YES;
}
}

When I try and save it returns the errors: -[NSConcreteMutableData writeToURL:ofType:error:]: unrecognized selector sent to instance 0x10016d900 -[NSConcreteMutableData writeToURL:ofType:error:]: unrecognized selector sent to instance 0x10016d900. I tired using a plain NSString and that didn't work either.

Thanks for any help

nosedive25
  • 2,477
  • 5
  • 30
  • 45

1 Answers1

1

When I try and save it returns the errors: -[NSConcreteMutableData writeToURL:ofType:error:]: unrecognized selector sent to instance 0x10016d900

That's because an NSMutableData doesn't respond to that message. Only documents respond to that message.

You need to send your data object a message it does respond to, such as writeToURL:options:error:.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • Okay I did that but now I logged the URL and found out its trying to write to the file /private/var/folders/sP/sPqwIQYwEi0lwleME5D8AE+++TI/TemporaryItems/(A Document Being Saved By MyApp 18)/Untitled.html Do you have any idea where is it getting this path from? – nosedive25 Nov 17 '10 at 01:34
  • http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSDocument_Class/Reference/Reference.html%23//apple_ref/doc/uid/20000008-BBCIFHHD – Peter Hosey Nov 17 '10 at 02:31