• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file


  • Subject: Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
  • From: Brian Clark <email@hidden>
  • Date: Mon, 16 Sep 2013 12:04:38 -0500

On Sep 16, 2013, at 4:38 AM, Mike Abdullah <email@hidden> wrote:

>
> On 14 Sep 2013, at 21:14, Brian Clark <email@hidden> wrote:
>
>> I'm hoping someone can suggest the correct way to deal with the following problem.
>>
>> For an image viewing app i display a file in the usual way in an NSDocument. setFileURL: is properly called by NSDocument's _initWithContentsOfURL:ofType:error:.
>>
>> I now want to display the next file in the folder, and move the old file to the Trash. To do this I do the necessary file reading tasks and call setFileURL: with the new file URL. I then move the old file to the trash (using NSFileManager 's trashItemAtURL:resultingItemURL:error: but using different methods gives the same result.)
>
> What are "the necessary file reading tasks"? Rather than call -setFileURL: yourself, have you tried calling -revertToContentsOfURL:ofType:error: instead? The top of the class documentation briefly notes that it should always be used for re-reading documents.

The "necessary tasks" are readFromURL:ofType:error: and the other chores associated with setting up the document state for the different image file.

Using -revertToContentsOfURL:ofType:error: instead does not work. After doing this NSDocument still seems to treat the old URL as the file's document, and I still get presentedItemDidMoveToURL: for the old file URL when it is moved to the Trash AFTER I-ve called revertToContentsOfURL:ofType:error:. While revertToContentsOfURL:ofType:error: may work correctly for the cases for which I guess it was intended (as described by the NSDocument Class Reference), it doesn't seem to work for this case, for reasons unknown.

The best work-around I've found is to add a file reference URL to my NSDocument subclass, and set it in an override of setFileURL:. Then in an override of presentedItemDidMoveToURL: I test if the saved file reference URL is the same as the new URL, and do nothing if they're not the same file. That seems to work, but it's a bit of a hack, and I'd really like to understand if NSDocument is simply broken in this regard, or why setFileURL: does not work and what is the correct and reliable way to change the URL for an open document.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
      • From: Kevin Perry <email@hidden>
References: 
 >Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file (From: Brian Clark <email@hidden>)
 >Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: Progress for archiving/dearchiving
  • Next by Date: Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
  • Previous by thread: Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
  • Next by thread: Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
  • Index(es):
    • Date
    • Thread