NSDocument -canAsynchronouslyWriteToURL::: never called

  • Keeping the list server busy while everyone else seem to have better things to do...

    Is there an magic trick to get the framework to actually call NSDocument's

    - (BOOL)canAsynchronouslyWriteToURL:(NSURL *)url ofType:(NSString *)typeName
    forSaveOperation:(NSSaveOperationType)saveOperation

    I'd like to do as the documentation suggests and put the document writing into a
    background tread (if you follow the little flood of NSDocument related messages
    you know why). Documentation says:

    --------
    The default implementation of this method returns NO. You are strongly
    encouraged to override it and make it return YES, after making sure your
    overrides of document writing methods can be safely invoked on a non-main
    thread, and making sure that unblockUserInteraction is invoked at some
    appropriate time during writing.
    --------

    There's no precondition listed, but there seems to be one as my override is
    never called. Why?

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
  • DeprecatedOn 6/10/12 7:21 PM, Markus Spoettl wrote:
    > Keeping the list server busy while everyone else seem to have better things to
    > do...
    >
    > Is there an magic trick to get the framework to actually call NSDocument's
    >
    > - (BOOL)canAsynchronouslyWriteToURL:(NSURL *)url ofType:(NSString *)typeName
    > forSaveOperation:(NSSaveOperationType)saveOperation
    >
    > I'd like to do as the documentation suggests and put the document writing into a
    > background tread (if you follow the little flood of NSDocument related messages
    > you know why). Documentation says:
    >
    > --------
    > The default implementation of this method returns NO. You are strongly
    > encouraged to override it and make it return YES, after making sure your
    > overrides of document writing methods can be safely invoked on a non-main
    > thread, and making sure that unblockUserInteraction is invoked at some
    > appropriate time during writing.
    > --------
    >
    > There's no precondition listed, but there seems to be one as my override is
    > never called. Why?

    Well, it suddenly started working and the reason is that apparently you need to have

    -saveToURL:ofType:forSaveOperation:completionHandler:

    overwritten. If you don't you just don't get to use background writing.
    Overwriting this method does the trick. One would think that the existence of

    -canAsynchronouslyWriteToURL:ofType:forSaveOperation:

    should be indication enough that one really, truly wants to use it. I have a
    suspicion that it has to do with my overwriting of

    -saveToURL:ofType:forSaveOperation:error:

    which as of 10.7 is deprecated in favor of a 10.7 version:

    -saveToURL:ofType:forSaveOperation:completionHandler:

    Of course that's no good if you want to support 10.6 as well.

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
  • On 6/10/12 7:45 PM, Markus Spoettl wrote:
    > Well, it suddenly started working and the reason is that apparently you need to
    > have
    >
    > -saveToURL:ofType:forSaveOperation:completionHandler:
    >
    > overwritten. If you don't you just don't get to use background writing.
    > Overwriting this method does the trick. One would think that the existence of
    >
    > -canAsynchronouslyWriteToURL:ofType:forSaveOperation:
    >
    > should be indication enough that one really, truly wants to use it. I have a
    > suspicion that it has to do with my overwriting of
    >
    > -saveToURL:ofType:forSaveOperation:error:
    >
    > which as of 10.7 is deprecated in favor of a 10.7 version:
    >
    > -saveToURL:ofType:forSaveOperation:completionHandler:
    >
    > Of course that's no good if you want to support 10.6 as well.

    Final episode in this epic play...

    The documentation on

    -saveToURL:ofType:forSaveOperation:completionHandler:

    states:

    --------
    For backward binary compatibility with Mac OS X v10.6 and earlier, the default
    implementation of this method instead invokes
    saveToURL:ofType:forSaveOperation:error: if that method is overridden and this
    one is not, and it passes any error to the completion handler.
    --------

    Which I guess is what they should also put into -canAsynchronouslyWriteToURL::

    Documentation enhancement suggestion filed.

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
  • On Jun 10, 2012, at 1:45 PM, Markus Spoettl wrote:

    > DeprecatedOn 6/10/12 7:21 PM, Markus Spoettl wrote:
    >> Keeping the list server busy while everyone else seem to have better things to
    >> do...
    >>
    >> Is there an magic trick to get the framework to actually call NSDocument's
    >>
    >> - (BOOL)canAsynchronouslyWriteToURL:(NSURL *)url ofType:(NSString *)typeName
    >> forSaveOperation:(NSSaveOperationType)saveOperation
    >>
    >> I'd like to do as the documentation suggests and put the document writing into a
    >> background tread (if you follow the little flood of NSDocument related messages
    >> you know why). Documentation says:
    >>
    >> --------
    >> The default implementation of this method returns NO. You are strongly
    >> encouraged to override it and make it return YES, after making sure your
    >> overrides of document writing methods can be safely invoked on a non-main
    >> thread, and making sure that unblockUserInteraction is invoked at some
    >> appropriate time during writing.
    >> --------
    >>
    >> There's no precondition listed, but there seems to be one as my override is
    >> never called. Why?
    >
    > Well, it suddenly started working and the reason is that apparently you need to have
    >
    > -saveToURL:ofType:forSaveOperation:completionHandler:
    >
    > overwritten. If you don't you just don't get to use background writing. Overwriting this method does the trick. One would think that the existence of

    This is one of the "joys" of Mac development I've seen.  Class methods are called that you never know about and you have to override stuff that you never knew were parts of the class, let alone are even called.

    Glad you got everything working.
  • On 6/10/12 9:21 PM, Alex Zavatone wrote:
    > This is one of the "joys" of Mac development I've seen.  Class methods are
    > called that you never know about and you have to override stuff that you
    > never knew were parts of the class, let alone are even called.

    To be fair it is documented, just not were I was looking.

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
  • On 10 Jun 2012, at 10:45, Markus Spoettl wrote:

    > DeprecatedOn 6/10/12 7:21 PM, Markus Spoettl wrote:
    >> Keeping the list server busy while everyone else seem to have better things to
    >> do...
    >>
    >> Is there an magic trick to get the framework to actually call NSDocument's
    >>
    >> - (BOOL)canAsynchronouslyWriteToURL:(NSURL *)url ofType:(NSString *)typeName
    >> forSaveOperation:(NSSaveOperationType)saveOperation
    >>
    >> I'd like to do as the documentation suggests and put the document writing into a
    >> background tread (if you follow the little flood of NSDocument related messages
    >> you know why). Documentation says:
    >>
    >> --------
    >> The default implementation of this method returns NO. You are strongly
    >> encouraged to override it and make it return YES, after making sure your
    >> overrides of document writing methods can be safely invoked on a non-main
    >> thread, and making sure that unblockUserInteraction is invoked at some
    >> appropriate time during writing.
    >> --------
    >>
    >> There's no precondition listed, but there seems to be one as my override is
    >> never called. Why?
    >
    > Well, it suddenly started working and the reason is that apparently you need to have
    >
    > -saveToURL:ofType:forSaveOperation:completionHandler:
    >
    > overwritten. If you don't you just don't get to use background writing. Overwriting this method does the trick. One would think that the existence of
    >
    > -canAsynchronouslyWriteToURL:ofType:forSaveOperation:
    >
    > should be indication enough that one really, truly wants to use it. I have a suspicion that it has to do with my overwriting of
    >
    > -saveToURL:ofType:forSaveOperation:error:
    >
    > which as of 10.7 is deprecated in favor of a 10.7 version:
    >
    > -saveToURL:ofType:forSaveOperation:completionHandler:
    >
    > Of course that's no good if you want to support 10.6 as well.

    Do you override any of the old -save… methods? If so, the document architecture figures they need to be called, so won’t attempt an async save.
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today