I realized yesterday that my app doesn’t mark its data structures as clean
(saved) after a save operation, and I’m trying to find the right place to do
that.
My NSDocument subclass implements saveToURL and fileWrapperOfType. Intuitively
I thought I could probably mark things as saved at the end of saveToURL if no
error occurs.
But if I try to do it as shown below, the compiler crashes with the error
message “swiftc failed with exit code 1”:
override func saveToURL(
url:NSURL,
ofType typeName:String,
forSaveOperation saveOperation:
NSSaveOperationType,
completionHandler:(NSError!) -> Void
) {
// <snip> Here I prepare my data structures for saving
//super.saveToURL( url, ofType:typeName, forSaveOperation:saveOperation,
completionHandler:completionHandler )
super.saveToURL(
url,
ofType:typeName,
forSaveOperation:saveOperation,
completionHandler:{
( error:NSError! ) -> Void in {
completionHandler( error )
// TODO: If no error, mark data structures as "clean"
}
}
)
}
As you can see, I’m attempting to wrap the passed-in completion handler, over
which I may have no control, in my own completion handler which will both call
the existing one and add mark my data structures. I couldn’t get the syntax to
work as a trailing closure, so I added the closure as an argument—but of course
I still might have the signature wrong . . .
(I’m also concerned about the way the completion handler demands an NSError
object, even though the documentation says it could be nil when no error
occurs.)
I think it most likely I’m doing this in the wrong place. But what’s the right
place? Overriding NSDocument’s setFileModificationDate() would seem like the
best way, but the NSDocument Programming guide says messages are sent to
setFileURL:, setFileType: and setFileModificationDate: “if appropriate,” so I’m
not sure I can count on getting that message.
What’s your advice?
—
Charles
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]