Posts

Post marked as solved
6 Replies
2.0k Views
Please can you help me with this problem 😟I'm pressing a button that segue into a second view controller ( modal sheet) that trigger an intensive calcucaltion process using viewDidLoad.The first problem was that once I press the button in the first view controller it freezes ( or get stuck) for 3 to 4 seconds ( going through the clauclation loops) before it segue into the second view controller and show the results of the calculation in a tableView.So I had to put an activity indicator and place the caclucaltion process in the background thread using Dispatchqueue, then put UI activity in the main thread to avoid the button freezing.The outcome if this was pressing the button in the first view controller, the second view controller ( modal sheet) pops up instantly with an activity indicator spinning and then calculation results gets viewed in the tableview!!Everything seems to be perfect, so I tried to test it again by dismissing the modal sheet by pulling it down to get back to the first view controller and press the button once more, at this moment it crashes showing : "fatal error: index out of range" and it keeps doing it each time I run it again!if I remove the dispatch queue and the activity indicator ( spinner), everything works but with a freezed button for 3-4 seconds and then get the results. I can do this multiple times with no crash or index out or range. Only when I put the disptachQueue, it works one time then it crashes the second time.Sometime it works twice or three times then it crashes again, I realy can't get my head around it !!!It feels to me that somehow the backgorund thread is keeping some memory and not clearing the table after dismissing the modal sheet but I can't find any clue how to fix this or to prove it.below is sample of the code : // THE SECOND VIEW CONTROLLER class PressurePipeResultsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var spinner: UIActivityIndicatorView! func startSpinner () { spinner.startAnimating() } func stopSpinner () { spinner.stopAnimating() } func fillVC () { let PW = round((PumpPowerkW(flow: finalFlow, p: density, dp: PdTotal, ef: finalEff))*100)/100 PumpPower.text = String ("Pump Power = \(PW) kw @ \(finalEff) % eff ") PressurePipeHead.text = ("\(PdTotal) bar") PressurePipeFlow.text = String("\(finalFlow) litre/min") } //below function is filling the result table func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return PdArray.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ResultCell", for: indexPath) // row filler let Pd = PdArray[indexPath.row] let Fname = FittingName [indexPath.row] let Fnumber = FittingNo [indexPath.row] // to translate the value of friction to material name through a loop in dictionary cell.textLabel?.text = "\(Fname) " + "\(Fnumber) " + "ΔP: \(Pd) bar" return cell } override func viewDidLoad() { super.viewDidLoad() startSpinner() DispatchQueue.global(qos: .background).async { // list of the matrix claculations to be triggered in sequence self.matEquation1 () self.matEquation2 () self.matEquation3 () self.efmatEquation1() self.efmatEquation2() self.efmatEquation3() self.pipelyKitAlgorithmCHECK () self.effeciencyValue () DispatchQueue.main.async { // presenting the results of the calculation into the UI self.fillVC() self.tableview.reloadData() self.hideKeyboardWhenTappedAround() self.stopSpinner() } } } }
Posted
by Ali-BMZ.
Last updated
.
Post marked as solved
4 Replies
470 Views
I'm trying to make a hydraulic engineering app for iPad, where you can create a network of lines intersecting with each other in a 2D environment like vectors and vertices and to be able to click them and edit the data base associated with each line or delete it, the app will calculate hydraulic flows and pressures through the network. I'm new to swift and want to know whats the best way to approach it using swift frameworks and calsses? I'm stuck on how to create the graphical vectors (objects) that I can interact with them and add data associated with each line! do you think that Metal is the way to go? the hydraulic calculations behind it will use matrix operations and I found a way through Accelerate frame work, as for data management I worked on core data and it looks great, but I'm stuck in the graphical part on how to create the line from two points and be able to click and interact with it like a button. To be fair it was very hard to find documentations on matrices operations ( bigger than a 4x4 matrix) and now the graphical part looks even harder! so please any help will be appreciated 🙂
Posted
by Ali-BMZ.
Last updated
.