save(to:ofType:for:delegate:didSave:contextInfo:)
Saves the contents of the document to a file or file package located by a URL, that is formatted to a specified type, for a particular kind of save operation.
Declaration
func save(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)Parameters
- url:
The location of the file or file package to which the document contents are saved.
- typeName:
The string that identifies the document type.
- saveOperation:
The type of save operation.
- delegate:
The delegate to which the selector message is sent.
- didSaveSelector:
The selector of the message sent to the delegate.
- contextInfo:
Object passed with the callback to provide any additional context information.
Discussion
When saving is completed, regardless of success or failure, the method sends the message selected by didSaveSelector to the delegate, with the contextInfo as the last argument. The method selected by didSaveSelector must have the same signature as:
- (void)document:(NSDocument *)document didSave:(BOOL)didSaveSuccessfully contextInfo:(void *)contextInfo;The default implementation of this method invokes [self saveToURL:absoluteURL ofType:typeName forSaveOperation:saveOperation error:&anError] and, if false is returned, presents the error to the user in a document-modal panel before messaging the delegate.
See Also
Writing the Document’s Content
canAsynchronouslyWrite(to:ofType:for:)unblockUserInteraction()write(to:ofType:)writeSafely(to:ofType:for:)fileWrapper(ofType:)data(ofType:)write(to:ofType:for:originalContentsURL:)save(to:ofType:for:completionHandler:)fileAttributesToWrite(to:ofType:for:originalContentsURL:)NSDocument.SaveOperationType