david_rosenberg

Swift program with minimal user interface

May 29th, 2015
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.56 KB | None | 0 0
  1. // NOTE: This is NOT an example of a good working program! It is an incomplete
  2. // badly structured program. It is posted here because I'm asking for help with it
  3. // - not offering it as an example to be followed.
  4.  
  5. // This program compiles and executes, but it is less than half implemented.
  6. // There are comments describing logic which hasn't been written yet.
  7.  
  8. // Xcode produces the warning message "This application is modifying the
  9. // autolayout engine from a background thread, which can lead to engine
  10. // corruption and weird crashes. This will cause an exception in a future release."
  11.  
  12. // The "read a line from the input file, do an HTTP POST, wait for a response,
  13. // manipulate the data, write a line to the output file, and loop back to read
  14. // the next input line" loop (which isn't a loop yet) really wants to run
  15. // synchronously and the only user interface should be "Pause" and "Quit"
  16. // buttons and a window where the program updates counts of what it has done.
  17.  
  18. // The current problems are:
  19. // 1. I don't know how to make the loop described above run synchronously -
  20. // that is, after issuing the HTTP POST, waiting for the response and
  21. // then processing the response as soon as we get it.
  22. // 2. I can get paths to the input and output files, but I can't read
  23. from or write to them.
  24. // 3. I don't know how to set up a window and update the record counts
  25. displayed there.
  26. // 4. I don't know how to setup and interact with the "Pause" and "Quit"
  27. // buttons.
  28.  
  29.  
  30.  
  31. // AppDelegate.swift
  32. // Test App
  33. //
  34. // Created by David Rosenberg on 5/29/15.
  35. // Copyright (c) 2015 David Rosenberg. All rights reserved.
  36.  
  37. import Cocoa
  38.  
  39. // Define global variables
  40. var debug: Bool = true
  41. var OutputPathString: String = ""
  42. var responseString: NSString = ""
  43.  
  44. @NSApplicationMain
  45. class AppDelegate: NSObject, NSApplicationDelegate {
  46.  
  47. @IBOutlet weak var window: NSWindow!
  48.  
  49. func applicationDidFinishLaunching(aNotification: NSNotification) {
  50. // Insert code here to initialize your application
  51. // Initialize application constants
  52.  
  53. var err: NSError?
  54.  
  55. let suffixes: Set<String> = ["ARTERY", "AVE", "BLVD", "CIR", "CT", "DR", "FRWY", "HWY", "LN", "PARK", "PKWY", "PIKE", "PL", "RD", "ST", "SQ", "TER", "TRL", "WAY"]
  56.  
  57. let regex0: NSRegularExpression = NSRegularExpression(pattern: "\\A.*<b>District Representatives:</b>.*href=\"http://www\\.sec\\.state\\.ma\\.us/ele/eledist/con11idx\\.htm#D[1-9]\" target=\"_blank\">(.*?)</a>.*href=\"http://www\\.sec\\.state\\.ma\\.us/ele/eledist/sen11idx\\.htm#[0-9]{0,5}[a-z]{1,20}\" target=\"_blank\">(.*?)</a>.*\"http://www\\.sec\\.state\\.ma\\.us/ele/eledist/reps11idx\\.htm#[a-z]{1,13}[0-9]{0,2}\" target=\"_blank\">(.*?)</a>.*\\z", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  58. let regex1: NSRegularExpression = NSRegularExpression(pattern: "<b>District Representatives:</b>", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  59. let regex2: NSRegularExpression = NSRegularExpression(pattern: "No records found. Use these tips for better results:", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  60. let regex3: NSRegularExpression = NSRegularExpression(pattern: "Your search produced several results.", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  61. let regex4: NSRegularExpression = NSRegularExpression(pattern: "Required: enter a street name</li><li>Required: select a city or town, or enter a zip code", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  62. let regex5: NSRegularExpression = NSRegularExpression(pattern: "Required: enter a street name", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  63. let regex6: NSRegularExpression = NSRegularExpression(pattern: "Required: select a city or town, or enter a zip code", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  64. let regex7: NSRegularExpression = NSRegularExpression(pattern: "^^(\\d{4,5}+)[ -]?+\\d*$", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  65. let regex8: NSRegularExpression = NSRegularExpression(pattern: "^\\d*$", options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: nil)!
  66.  
  67. let cities: Dictionary<String, String> = ["ABINGTON": "1", "ACTON": "2", "ACUSHNET": "3", "ADAMS": "4", "AGAWAM": "5", "ALFORD": "6", "AMESBURY": "7", "AMHERST": "8"]
  68.  
  69.  
  70. let bodyInitial: String = "This isn't the real initial part of the body"
  71.  
  72. let bodyCity: String = "&ctl00%24MainContent%24ddlCityTown="
  73. let bodySuffix: String = "&ctl00%24MainContent%24ddlStreetSuffix="
  74. let bodyStreet: String = "&ctl00%24MainContent%24txtStreetName="
  75. let bodyNumber: String = "&ctl00%24MainContent%24txtStreetNo="
  76. let bodyZip: String = "&ctl00%24MainContent%24txtZip="
  77.  
  78. let wdivURL = NSURL(string: "http://NotTheRealDomain.com")
  79. let request = NSMutableURLRequest(URL:wdivURL!)
  80. request.HTTPMethod = "POST"
  81. // request.setValue("en-us", forHTTPHeaderField: "Accept-Language")
  82. // request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
  83. // request.setValue("*/*", forHTTPHeaderField: "Accept")
  84. // request.setValue("gzip, deflate", forHTTPHeaderField: "Accept-Encoding")
  85. // or
  86. // request.addValue("en-us", forHTTPHeaderField: "Accept-Language")
  87. // request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
  88. // request.addValue("*/*", forHTTPHeaderField: "Accept")
  89. // request.addValue("gzip, deflate", forHTTPHeaderField: "Accept-Encoding")
  90.  
  91.  
  92. // Declare and initialize application variables
  93.  
  94. var session = NSURLSession.sharedSession()
  95.  
  96. var InputRecInt: Int = 0
  97. var SuccessInt: Int = 0
  98. var EmptyInt: Int = 0
  99. var SkippedInt: Int = 0
  100. var ValidatedInt: Int = 0
  101. var BadInputInt: Int = 0
  102. var BadLookupInt: Int = 0
  103.  
  104. var InputRecStr: String
  105. var SuccessStr: String
  106. var EmptyStr: String
  107. var SkippedStr: String
  108. var ValidatedStr: String
  109. var BadInputStr: String
  110. var BadLookupStr: String
  111.  
  112. var congDist: String
  113. var senDist: String
  114. var repDist: String
  115. var comment: String
  116. var inputTab = [String]()
  117. var outputRecord: String
  118. var inputRecordForWriting: String
  119. var fatal: Bool // A fatal issue was noted
  120. var issue: Bool // a non-fatal issue was noted
  121.  
  122. var myAlert:NSAlert = NSAlert()
  123.  
  124. // Get input file
  125. var openPanel = NSOpenPanel()
  126. openPanel.prompt = "Input"
  127. openPanel.allowsMultipleSelection = false
  128. openPanel.canChooseDirectories = false
  129. openPanel.canCreateDirectories = false
  130. openPanel.canChooseFiles = true
  131. openPanel.title = "Select the (tab-delimited) input file"
  132. var openResult = openPanel.runModal()
  133. // If user cancels, terminate program
  134. if openResult == NSFileHandlingPanelCancelButton {
  135. NSApplication.sharedApplication().terminate(0)
  136. }
  137. //If we got here, the user must have selected a file
  138. let InputPathString: String = openPanel.URL!.absoluteString!
  139. let inFile: NSFileHandle? = NSFileHandle(forReadingAtPath: InputPathString)
  140. if inFile == nil {
  141. println("Couldn't open input file at \(InputPathString)")
  142. } else {
  143. inFile?.closeFile()
  144. }
  145. let InputFilename = openPanel.URL!.lastPathComponent!
  146. // Get output file
  147. var samefile: Bool
  148.  
  149. do {
  150. var savePanel = NSSavePanel()
  151. savePanel.canCreateDirectories = true
  152. savePanel.prompt = "Output"
  153. savePanel.title = "Select the output file to be written"
  154. savePanel.nameFieldStringValue = InputFilename + ".output"
  155. savePanel.directoryURL = openPanel.URL
  156. // myAlert.messageText = "openPanel.URL is \(openPanel.URL)"
  157. // myAlert.runModal()
  158. // myAlert.messageText = "savePanel.directoryURL is \(savePanel.directoryURL)\nsavePanel.nameFieldStringValue is \(savePanel.nameFieldStringValue)"
  159. // myAlert.runModal()
  160.  
  161. var saveResult = savePanel.runModal()
  162. // myAlert.messageText = "Output file name is \(savePanel.URL)"
  163. // myAlert.runModal()
  164. // If user cancels, terminate program
  165. if saveResult == NSFileHandlingPanelCancelButton {
  166. NSApplication.sharedApplication().terminate(0)
  167. }
  168. //If we got here, the user must have selected a file
  169. OutputPathString = savePanel.URL!.absoluteString!
  170. samefile = OutputPathString.uppercaseString == InputPathString.uppercaseString
  171. myAlert.messageText = "OutputPathString is \(OutputPathString)\nInputPathString is \(InputPathString)\nsamefile is \(samefile )"
  172. myAlert.runModal()
  173. if samefile {
  174. myAlert.messageText = "The output may NOT be written to the input file. Please select a different output file."
  175. myAlert.runModal()
  176. }
  177. } while samefile
  178.  
  179. NSFileManager.defaultManager().createFileAtPath(OutputPathString, contents: NSData(), attributes: nil)
  180. let outFile: NSFileHandle? = NSFileHandle(forWritingAtPath: OutputPathString)
  181. if outFile == nil {
  182. println("Couldn't open output file")
  183. } else {
  184. println("Output file looks OK")
  185. }
  186.  
  187. // Set up display window
  188. // Read a line from the input file
  189. // While not at EOF
  190.  
  191. // Set up display window
  192. // Read a line from the input file into inputRecord
  193. // While not at EOF
  194.  
  195. var inputRecord: String = ""
  196.  
  197. inputRecordForWriting = inputRecord
  198.  
  199. ProcessARecord: do {
  200. // Increment input record count
  201. ++InputRecInt
  202.  
  203. // initialize per record variables
  204. fatal = false
  205. issue = false
  206. congDist = ""
  207. senDist = ""
  208. repDist = ""
  209. comment = ""
  210. inputTab = [String]()
  211. outputRecord = ""
  212.  
  213. // If input record is empty, write out "Failure, Input, Input record was empty", increment empty counter, and "Break ProcessARecord"
  214. if inputRecord.isEmpty {
  215. fatal = true
  216. congDist = "Failure"
  217. senDist = "Input"
  218. repDist = "Input record was empty"
  219. // comment =
  220. ++EmptyInt
  221. break ProcessARecord
  222. }
  223. // Store the input record in the inputTab array
  224. inputTab = inputRecord.componentsSeparatedByString("\t")
  225. // inputTab[0] is WDIV Skip Flag
  226. // inputTab[1] is WDIV Street Number
  227. // inputTab[2] is WDIV Street Name
  228. // inputTab[3] is WDIV Street Suffix
  229. // inputTab[4] is WDIV City/Town
  230. // inputTab[5] is ZIP
  231. // inputTab[6] is State
  232.  
  233. var arrayCount: Int = inputTab.count
  234.  
  235. // If input array has fewer than seven elements, add enough empty elements,
  236. // so that it has seven elements
  237. for var index = arrayCount; index < 7; ++index {
  238. inputTab.append("")
  239. }
  240. // For each element of the first seven elements of the array, trim leading and trailing whitespace and make it uppercase
  241. for index in 0...6 {
  242. inputTab[index] = inputTab[index].stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
  243. inputTab[index] = inputTab[index].uppercaseString
  244. }
  245. // If inputTab[0] (1st input field) is "S", write out "Skipped", increment skipped counter, and "Break ProcessARecord"
  246. if inputTab[0] == "S" {
  247. fatal = true
  248. congDist = "Skipped"
  249. // senDist =
  250. // repDist =
  251. // comment =
  252. ++SkippedInt
  253. break ProcessARecord
  254. }
  255.  
  256. // If InputRec[6] is not empty & is not "MA", note (in problem flags) that the state is not MA, set Fatal = true
  257. if !inputTab[6].isEmpty && inputTab[6] != "MA" {
  258. fatal = true
  259. if !comment.isEmpty {
  260. comment += "; "
  261. }
  262. comment += "The state isn't Massachusetts"
  263. if inputTab[0] != "L" {
  264. congDist = "Not MA"
  265. // senDist =
  266. // repDist =
  267. // comment =
  268. ++SkippedInt
  269. break ProcessARecord
  270. }
  271. }
  272.  
  273. // StreetNumber = InputRec[1] (2nd input field)
  274. if regex8.rangeOfFirstMatchInString(inputTab[1] as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, count(inputTab[1]))).location == NSNotFound {
  275. fatal = true
  276. if !comment.isEmpty {
  277. comment += "; "
  278. }
  279. comment += "Street number must be numeric (or null)"
  280. }
  281. if inputTab[1].isEmpty {
  282. issue = true
  283. if !comment.isEmpty {
  284. comment += "; "
  285. }
  286. comment += "There is no street number"
  287. }
  288.  
  289. // StreetName = InputRec[2] (3rd input field)
  290. if inputTab[2].isEmpty {
  291. fatal = true
  292. if !comment.isEmpty {
  293. comment += "; "
  294. }
  295. comment += "A street name is required"
  296. }
  297. // Percent-Escape StreetName
  298. var street1 = inputTab[2].stringByReplacingOccurrencesOfString("%", withString: "%25", options: NSStringCompareOptions.LiteralSearch, range: nil)
  299. var street2 = street1.stringByReplacingOccurrencesOfString("&", withString: "%26", options: NSStringCompareOptions.LiteralSearch, range: nil)
  300. street1 = street2.stringByReplacingOccurrencesOfString("'", withString: "%27", options: NSStringCompareOptions.LiteralSearch, range: nil)
  301. street2 = street1.stringByReplacingOccurrencesOfString("+", withString: "%2B", options: NSStringCompareOptions.LiteralSearch, range: nil)
  302. street1 = street2.stringByReplacingOccurrencesOfString("/", withString: "%2F", options: NSStringCompareOptions.LiteralSearch, range: nil)
  303. inputTab[2] = street1.stringByReplacingOccurrencesOfString("=", withString: "%3D", options: NSStringCompareOptions.LiteralSearch, range: nil)
  304.  
  305. // StreetSuffix = InputRec[3] (4th input field)
  306. // Test that a suffix is in the set of valid suffixes
  307. if !inputTab[3].isEmpty && !suffixes.contains(inputTab[3]) {
  308. fatal = true
  309. if !comment.isEmpty {
  310. comment += "; "
  311. }
  312. comment += "\(inputTab[3]) is not a valid street suffix"
  313. }
  314.  
  315. // if InputRec[4] (5th input field) is empty, CityTown = "-1"
  316. if inputTab[4].isEmpty {
  317. issue = true
  318. if !comment.isEmpty {
  319. comment += "; "
  320. }
  321. comment += "There is no town/city"
  322. inputTab[4] = "-1"
  323. } else {
  324. // Test that a city is in the dictionary of valid cities
  325. if var CityNumber = cities[inputTab[4]] {
  326. inputTab[4] = CityNumber
  327. } else {
  328. issue = true
  329. if !comment.isEmpty {
  330. comment += "; "
  331. }
  332. comment += "\(inputTab[4]) is not a valid city/town"
  333. inputTab[4] = "-1"
  334. }
  335. }
  336. if inputTab[5].isEmpty {
  337. issue = true
  338. if !comment.isEmpty {
  339. comment += "; "
  340. }
  341. comment += "There is no ZIP Code"
  342. } else {
  343. // Now for some regular expression fun with the ZIP code
  344. // Remove a space or hypen and any digits following it from InputRec[5]
  345. // if InputRec[5] is fewer than four characters, is more than five characters, or
  346. // contains any non-digits, note (in problem flags) that the ZIP code is invalid
  347. // if InputRec[5] is exactly four characters, prepend a leading zero
  348. var newZIP: String = ""
  349. if regex7.rangeOfFirstMatchInString(inputTab[5] as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, count(inputTab[5]))).location == NSNotFound {
  350. issue = true
  351. inputTab[5] = ""
  352. if !comment.isEmpty {
  353. comment += "; "
  354. }
  355. comment += "The ZIP Code is invalid"
  356. } else {
  357. newZIP = regex7.stringByReplacingMatchesInString(inputTab[5], options: NSMatchingOptions.allZeros, range: NSMakeRange(0, count(inputTab[5])), withTemplate: "$1")
  358. if count(newZIP) == 4 {
  359. inputTab[5] = "0" + newZIP
  360. } else {
  361. inputTab[5] = newZIP
  362. }
  363. }
  364. }
  365.  
  366. // If CityTown == "-1" and ZIPcode is empty, set Fatal = true
  367. if inputTab[4] == "-1" && inputTab[5].isEmpty {
  368. fatal = true
  369. if !comment.isEmpty {
  370. comment += "; "
  371. }
  372. comment += "Either a city/town or a ZIP code is required"
  373. }
  374.  
  375. // If InputRec[0] is "I", we're done
  376. if inputTab[0] == "I" {
  377. if fatal {
  378. congDist = "Failure"
  379. senDist = "Input"
  380. repDist = "See comments"
  381. // comment =
  382. ++BadInputInt
  383. } else if issue {
  384. congDist = "Checked"
  385. senDist = "Some non-fatal issue(s)"
  386. repDist = "See comments"
  387. // comment =
  388. ++ValidatedInt
  389. } else {
  390. congDist = "Checked"
  391. senDist = "No issues"
  392. repDist = "Congratulations"
  393. // comment =
  394. ++ValidatedInt
  395. }
  396. break ProcessARecord
  397. }
  398.  
  399. // If (Fatal = false or InputRec[0] is "L"), we will do a lookup on the web site
  400. if inputTab[0] != "L" && fatal {
  401. congDist = "Failure"
  402. senDist = "Input"
  403. repDist = "See comments"
  404. // comment =
  405. break ProcessARecord
  406. }
  407. // Now we are actually going to do an HTTP POST
  408. // Assemble HTTP POST
  409.  
  410. var bodyData: String = bodyInitial + bodyCity + inputTab[4] + bodySuffix + inputTab[3] + bodyStreet + inputTab[2] + bodyNumber + inputTab[1] + bodyZip + inputTab[5]
  411. request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
  412. // Execute HTTP POST
  413. let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {data, response, error in
  414. if error != nil {
  415. println("error=\(error)")
  416. return
  417. }
  418. // Get the response to the HTTP POST
  419. var responseString = NSString(data: data, encoding: NSUTF8StringEncoding)!
  420. outFile?.writeData(responseString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!)
  421. outFile?.closeFile()
  422. if regex1.rangeOfFirstMatchInString(responseString as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, responseString.length)).location != NSNotFound {
  423. println("Districts exist")
  424. var results: String = regex0.stringByReplacingMatchesInString(responseString as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, responseString.length), withTemplate: "$1\t$2\t$3")
  425. var resultsTab: [String] = results.componentsSeparatedByString("\t")
  426. congDist = resultsTab[0]
  427. senDist = resultsTab[1]
  428. repDist = resultsTab[2]
  429. ++SuccessInt
  430. // myAlert.messageText = results
  431. // myAlert.runModal()
  432. // Logically, we want to break out of the ProcessARecord block
  433. // here. But we can't because we are in a separate task.
  434. // Fortunately, just exiting this if "else" chain will finish
  435. // this task and be the equivalent of breaking out of the
  436. // ProcessARecord block.
  437. // break ProcessARecord
  438.  
  439. } else if regex2.rangeOfFirstMatchInString(responseString as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, responseString.length)).location != NSNotFound {
  440. congDist = "Failure"
  441. senDist = "Lookup"
  442. repDist = "No records found"
  443. ++BadLookupInt
  444.  
  445. } else if regex3.rangeOfFirstMatchInString(responseString as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, responseString.length)).location != NSNotFound {
  446. congDist = "Failure"
  447. senDist = "Lookup"
  448. repDist = "Ambiguous results"
  449. ++BadLookupInt
  450.  
  451. } else if regex4.rangeOfFirstMatchInString(responseString as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, responseString.length)).location != NSNotFound {
  452. congDist = "Failure"
  453. senDist = "Lookup"
  454. repDist = "No street, city/town or ZIP code"
  455. ++BadLookupInt
  456.  
  457. } else if regex5.rangeOfFirstMatchInString(responseString as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, responseString.length)).location != NSNotFound {
  458. congDist = "Failure"
  459. senDist = "Lookup"
  460. repDist = "No street name"
  461. ++BadLookupInt
  462.  
  463. } else if regex6.rangeOfFirstMatchInString(responseString as String, options: NSMatchingOptions.allZeros, range: NSMakeRange(0, responseString.length)).location != NSNotFound {
  464. congDist = "Failure"
  465. senDist = "Lookup"
  466. repDist = "No city/town or ZIP code"
  467. ++BadLookupInt
  468.  
  469. } else {
  470. congDist = "Failure"
  471. senDist = "Lookup"
  472. repDist = "Unexpected response from web server"
  473. ++BadLookupInt
  474. myAlert.messageText = "The web site gave an unexpected response for line \(InputRecInt) in the input file. Please give a programmer this message (including the line number) and a copy of the input file."
  475. myAlert.runModal()
  476. } // End of test to see if we got districts
  477.  
  478. } // End of definition of task
  479. task.resume()
  480.  
  481. } while false // End of ProcessARecord block
  482.  
  483. // NOTE: In every case where an output record is being written, it is four leading fields followed by the entire input record.
  484. // Only for debugging purposes, write out the filelds that we sent (or could
  485. // have sent) to the web site at the beginning of the output record
  486. if debug && !inputRecord.isEmpty {
  487. outputRecord = inputTab[1] + "\t" + inputTab[2] + "\t" + inputTab[3] + "\t" + inputTab[4] + "\t" + inputTab[5] + "\t"
  488. } else {
  489. outputRecord = ""
  490. }
  491. // Write CongDist, SenDist, RepDist, Comment, followed by the input record to the output record
  492. outputRecord += congDist + "\t" + senDist + "\t" + repDist + "\t" + comment
  493. if !inputRecordForWriting.isEmpty { outputRecord += "\t" + inputRecordForWriting }
  494. // Update numbers being displayed
  495. // if Pause button clicked {
  496. // Change Pause button to Resume button
  497. // While Resume not clicked and Quit not clicked {
  498. // Wait one second
  499. // }
  500. // If Quit was clicked {
  501. // Close output file
  502. // Close input file
  503. // Terminate application
  504. // }
  505. // // If we got here, Resume must have been clicked
  506. // Change Resume button back to Pause button
  507. // }
  508. // if Quit button clicked {
  509. // Close output file
  510. // Close input file
  511. // Terminate application
  512. // }
  513. // Read a line from the input file
  514. // End of While loop that processes the input file
  515. // Close output file
  516. // Close input file
  517. // Remove Pause button
  518. // Change Quit button to Finish button
  519. // While Finish not clicked {
  520. // Wait one second
  521. // }
  522.  
  523. if false {
  524. // If we need to show the results in an Alert dialog
  525. InputRecStr = String(format:"%06d", InputRecInt)
  526. SuccessStr = String(format:"%06d", SuccessInt)
  527. EmptyStr = String(format:"%06d", EmptyInt)
  528. SkippedStr = String(format:"%06d", SkippedInt)
  529. ValidatedStr = String(format:"%06d", ValidatedInt)
  530. BadInputStr = String(format:"%06d", BadInputInt)
  531. BadLookupStr = String(format:"%06d", BadLookupInt)
  532.  
  533. var finalResult:NSAlert = NSAlert()
  534. finalResult.messageText = " Input records: \(InputRecStr)\n Successes: \(SuccessStr)\n Empty records: \(EmptyStr)\nSkipped records: \(SkippedStr)\n Only validated: \(ValidatedStr)\n Bad input: \(BadInputStr)\n Bad lookup: \(BadLookupStr)"
  535. finalResult.runModal()
  536. } // End of if false around the finaResults alert
  537.  
  538. // Terminate application
  539. // NSApplication.sharedApplication().terminate(0)
  540.  
  541.  
  542. } // End of applicationDidFinishLaunching
  543.  
  544. func applicationWillTerminate(aNotification: NSNotification) {
  545. // Insert code here to tear down your application
  546. }
  547. }
Advertisement
Add Comment
Please, Sign In to add comment