• 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: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?


  • Subject: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • From: Gilles Celli <email@hidden>
  • Date: Thu, 09 Feb 2012 21:23:33 +0100

Mike, Kyle,

Thanks for the quick answers!

Yes I'm targeting Mac OS X 10.6 and later so canConcurrentlyReadDocumentsOfType: is a welcome addition, I completely forgot that.

Strangely if I put the method canConcurrentlyReadDocumentsOfType: inside my NSDocument I get a warning when trying to open a document (It seems to be a QuickLook error ?) on Mac OS X 10.7.3:

[QL] QLError(): +[QLSeamlessDocumentOpener seamlessDocumentOpenerForURL:] should only be called in the main thread

Now for the cancel question: If I take the more traditional approach to cancel the operation inside readFromURL, should I fire up a new thread to check the flag's status ?

Gilles


On Feb 9, 2012, at 7:32 PM, Kyle Sluder wrote:

> On Thu, Feb 9, 2012 at 8:01 AM, Gilles Celli <email@hidden> wrote:
>> Hi,
>>
>> I searched the mailing-list but didn't find an answer….so sorry if this was posted before:
>>
>> I've setup a document based application which can read large ASCII data files (>150MB).
>>
>> When opening the document the method readFromURL:ofType:error is used which then opens a small feedback window
>> showing the file name and an animated  progress bar with a "Cancel" NSButton.
>
> If you're targeting Snow Leopard or later, you should override
> +canConcurrentlyReadDocumentsOfType: to return YES. That will cause
> -initWithContentsOfURL:ofType:error: (and therefore
> -readFromURL:ofType:error:) to execute on a background thread.
>
> Then you get to the canceling part. The traditional approach would be
> to set a flag when the user clicks Cancel, and periodically check this
> flag from within your -readFromURL:… implementation, returning an
> NSUserCancelledError if you detect it has been set.
>
> A more modern approach might be to use NSOperationQueue. Instead of a
> loop, -readFromURL:… would divide its work into operations and enqueue
> those on a queue. Clicking the Cancel button would enqueue an
> operation that would shut down the -readFromURL:'s operation queue and
> cause it to return an NSUserCancelledError.
>
> --Kyle Sluder


_______________________________________________

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: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
      • From: Jeffrey Oleander <email@hidden>
    • Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
      • From: Mike Abdullah <email@hidden>
References: 
 >How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Gilles Celli <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)
  • Next by Date: Odd behavior of NSItemReplacementDirectory
  • Previous by thread: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Next by thread: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Index(es):
    • Date
    • Thread