Help with a Swift OS X program

Steve Sisak steve.sisak at ioxperts.com
Tue Jun 2 14:05:53 EDT 2015


I just got back to Boston (2am) after a 9 hour drive and haven’t looked into the details, but if you want, I could probably throw together a session on NSURLSession and alternates and use this as an example.

BTW, it ought to be pretty trivial to preserve the illusion of synchronicity using blocks and dispatch queues.

Caveat: I’ve barely looked at Swift, so we’d have to meet in the middle.

HTH,

-Steve


> On Jun 2, 2015, at 7:53 AM, John Shockey <john at johncshockey.com> wrote:
> 
> David,
> 
> My apologies for not getting back to you more quickly. I started a
> response, but I'm working under a deadline and it swallowed me up before
> I finished it.
> 
> What I was working on was a bit longer, but what Erik said is correct,
> and along the same lines as I was writing.
> 
> Just because it's important, I'll repeat a part of what he said: You
> should never attempt to do synchronous (blocking) programming, and
> synchronous network programming in particular, on the main thread.
> 
> That leaves you at least three possibilities.
> 
> 1. Move the networking to an alternate thread. I don't think this will
> be the best choice. Among other things, you'd need to use lower level
> APIs if you really want to do your networking synchronously. Plus,
> synchronizing between threads allows all sorts of things to go wrong.
> Sometimes it's worth it to use threads, but it's probably too much work.
> 
> 2. Write a real command line utility, and a UI program that runs it in a
> separate process. There are times when this is a good approach, but it
> seems like way too much work in your situation.
> 
> 3. Do your networking asynchronously. It's fairly simple once you
> understand how it works, and there's no need for explicit threading.
> (Though Cocoa may use threads behind the scenes, you won't have to deal
> with it.) You will need to rearrange how you're doing things, but
> learning to do it the was Cocoa intends should be worth the effort.
> 
> Again, what Erik said is correct. I'm just a little more long-winded.
> <grin>
> 
> If you want help figuring out how to use NSURLSession, feel free to
> bring your questions to a meeting. We don't have a specific presentation
> scheduled this month, so there should be plenty of time. If you can't
> make it to a meeting, and if Erik hasn't already helped you
> sufficiently, take a look at the documentation for NSURLSession and
> friends, and then ask again here.
> 
> Good luck,
> 
> John
> 
> _______________________________________________
> MacTechGroup-discuss mailing list
> MacTechGroup-discuss at lists.mactechgroup.org
> http://lists.mactechgroup.org/mailman/listinfo/mactechgroup-discuss



More information about the MacTechGroup-discuss mailing list