Help with a Swift OS X program

Erik Price erikprice at gmail.com
Mon Jun 1 10:50:50 EDT 2015


David, please disregard this if you've already gotten some help or solved
your problem.

Speaking for myself, and possibly for others, it's easier to evaluate
whether I can help you if I can see the code you have so far. Do you (or
can you) post that code to a public source code repository somewhere?

At a high level, you are correct that NSURLSession is not designed to be
used synchronously, and if you've written your code with the assumption
that it works that way, you'll want to go back and rework things.
Typically, you would either create a completion block or a class that
conforms to the NSURLSessionDelegate protocol, and the NSURLSession will
call you back with either of these facilities to let you know when data has
been received. At that point, you can buffer the data in memory or write it
to the output file.

Good luck!

e

On Sun, May 31, 2015 at 1:12 PM, David M Rosenberg <rosenberg at acm.org>
wrote:

> I'm trying to write an OSX program in Swift. The program performs what is
> essentially a background function: reading a line from a tab-delimited
> input file, extracting information from that line and formating it into the
> body of an HTTP POST, executing the HTTP POST request, receiving the
> response, manipulating it, writing it as the next line in a tab-delimited
> output file, and looping back to read the next input line until we reach
> the end of the input file.
>
> It could have almost been a command line program. I wanted to give it a
> (minimal) user interface because I wanted the user to be able to browse the
> file system to select the input and output files, to have "Pause" and
> "Quit" buttons to control execution, to have a window in which to display
> status of what the program was doing, and maybe to give the user a little
> more control before starting the program (such as turning on debugging mode
> or telling it to just validate the input without actually doing the HTTP
> POST). I guess I also want the experience of writing a Swift program with a
> user interface.
>
> I have written the part of the program that does the work of formating
> input into the body of an HTTP POST, executing the HTTP POST request,
> receiving the response, manipulating it, and formating it to be written to
> the output file. The program doesn't have any user interface. It uses
> NSOpenPanel and NSSavePanel to allow the user select the input and output
> files, but at the moment I can't get it to actually read or write files.
> But the biggest problem is that it is written in a very non-object-oriented
> fashion. It basically has one large, synchronous "read, process, write"
> loop. The program uses NSURLSession.sharedSession to do the HTTP POST. The
> program wants to treat the HTTP POST as happening in the main loop and
> being blocked until a response arrives. But that isn't what the system
> wants to do. The system wants to run the NSURLSession in a separate
> asynchronous task. I need help in synchronizing the NSURLSession with my
> main loop. I'd also like to restructure the program to be object-oriented.
>
> I’m looking for someone who would be willing to provide some advice and
> guidance - perhaps during the next MacTech group meeting, perhaps after the
> meeting, perhaps on a separate occasion either in person, by phone or by
> E-Mail.
>
> Please contact me if you might be willing to help.
>
> Thanks.
>
> /David
> _______________________________________________
> MacTechGroup-discuss mailing list
> MacTechGroup-discuss at lists.mactechgroup.org
> http://lists.mactechgroup.org/mailman/listinfo/mactechgroup-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mactechgroup.org/pipermail/mactechgroup-discuss/attachments/20150601/d2852f6d/attachment.html>


More information about the MacTechGroup-discuss mailing list