nosedive25
nosedive25

Reputation: 2435

NSDocument writeToURL:, saving a simple html document

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

Upvotes: 0

Views: 967

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96333

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:.

Upvotes: 1

Related Questions