• 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: NSSharingService with Animated GIFs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSharingService with Animated GIFs?


  • Subject: Re: NSSharingService with Animated GIFs?
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 17 May 2014 03:47:25 -0500

On May 17, 2014, at 2:16 AM, Charles Carver wrote:

> Thanks for the tips! As I’m new to Cocoa, they’re all very helpful.

You're welcome.  I'm glad to help.


>> You should consider what happens if the server is slow to respond.  The above call will block until the image download is complete.  Better to use the asynchronous URL loading mechanisms in the frameworks (e.g. NSURLSession).
>
> While working on a similar image download method for a different part of my app, I also encountered the blocking nature of writeToURL. I Googled for a solution (not wanting to refactor my saving with NSURLSession), and found an SO question (http://stackoverflow.com/questions/16283652/understanding-dispatch-async) on dispatch_async.
>
> Per the top answer, I implemented the following...
>
> dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
> ...
> });
>
> …to handle the synchronistic nature of my file download/saving.
>
> Is this frowned upon?

Yes, somewhat.  It can be a quick-and-dirty solution, but it is a bit dirty.  In particular, the thread that services that task will end up blocked in the synchronous URL download operation.  A thread is a fairly expensive resource and it's being largely wasted.  It's doing little but waiting.

> Would it be more beneficial in the long run to use NSURLSession instead?

Yes.

Also, GCD has its own share of gotchas.  So, even if you use it, it's not necessarily as simple as just wrapping some code in a dispatch_async().  In particular, you need to make sure that any GUI-related code is shunted back to the main thread.  In your case, the NSSharingService stuff probably qualifies.

Regards,
Ken


_______________________________________________

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


References: 
 >Re: NSSharingService with Animated GIFs? (From: Charles Carver <email@hidden>)
 >Re: NSSharingService with Animated GIFs? (From: Ken Thomases <email@hidden>)
 >Re: NSSharingService with Animated GIFs? (From: Charles Carver <email@hidden>)
 >Re: NSSharingService with Animated GIFs? (From: Ken Thomases <email@hidden>)
 >Re: NSSharingService with Animated GIFs? (From: Charles Carver <email@hidden>)

  • Prev by Date: making NSView firstResponder/key
  • Next by Date: Re: making NSView firstResponder/key
  • Previous by thread: Re: NSSharingService with Animated GIFs?
  • Next by thread: DTS: how long for response?
  • Index(es):
    • Date
    • Thread