• 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: Kyle Sluder <email@hidden>
  • Date: Thu, 09 Feb 2012 10:32:55 -0800

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

  • Prev by Date: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Next by Date: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)
  • 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