Help with a Swift OS X program

David M Rosenberg rosenberg at acm.org
Sun May 31 13:12:23 EDT 2015


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


More information about the MacTechGroup-discuss mailing list