<div dir="ltr"><div>David, please disregard this if you've already gotten some help or solved your problem.</div><div><br></div>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?<div><br></div><div>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.</div><div><br></div><div>Good luck!</div><div><br></div><div>e</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 31, 2015 at 1:12 PM, David M Rosenberg <span dir="ltr"><<a href="mailto:rosenberg@acm.org" target="_blank">rosenberg@acm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
Please contact me if you might be willing to help.<br>
<br>
Thanks.<br>
<br>
/David<br>
_______________________________________________<br>
MacTechGroup-discuss mailing list<br>
<a href="mailto:MacTechGroup-discuss@lists.mactechgroup.org">MacTechGroup-discuss@lists.mactechgroup.org</a><br>
<a href="http://lists.mactechgroup.org/mailman/listinfo/mactechgroup-discuss" target="_blank">http://lists.mactechgroup.org/mailman/listinfo/mactechgroup-discuss</a><br>
</blockquote></div><br></div>