I'm attempting to make a specialized calculation app, but have absolutely no experience with swift or iOS development and some amount of experience in Java before starting this project up a few days ago.
I'm attempting to pass a struct variable from one view controller to another, and then gain those variables through instantiation.
Here's the code including the struct:
struct SSDCalcs {
var patientInput: String
var siteInput: String
var scriptInput: Double
var depthInput: Double
var fieldInput: Double
var length: Double
var width: Double
var squareInput: Double
}
//Change values of struct when enter key pressed
@IBAction func enterPressed(_ sender: Any) {
calcResults = SSDCalcs(patientInput: patientID.text!, siteInput: "fdfadsf", scriptInput: 5.0, depthInput: 6.0, fieldInput: 7.0, length: 8.0, width: 9.0, squareInput: 15.0)
}
//Initial delcaration of struct values (So the results page class doesn't complain about "calcResults" not yet existing"
var calcResults = SSDCalcs(patientInput: "Error: Wrong struct values", siteInput: "Error", scriptInput: 0.0, depthInput: 0.0, fieldInput: 0.0, length: 0.0, width: 0.0, squareInput: 0.0)
}
And here is my results page code from the other class:
func setValues() {
var SSDCalcs = SSDCalculation().calcResults
self.SSDPatientRef.text = "Patient ID: " + SSDCalcs.patientInput
self.SSDSiteRef.text = "Treatment Site: " + SSDCalcs.siteInput
self.SSDScriptRef.text = "Script (cGy): " + String(SSDCalcs.scriptInput)
self.SSDDepthRef.text = "Depth: " + String(SSDCalcs.depthInput)
self.SSDFieldRef.text = "Field Size: " + String(SSDCalcs.fieldInput)
self.SSDLengthRef.text = "Length: " + String(SSDCalcs.length)
self.SSDWidthRef.text = "Width: " + String(SSDCalcs.width)
self.SSDSqrRef.text = "Equivalent Square: " + String(SSDCalcs.squareInput)
}
No error is given when compiling or running the code... it just doesn't seem to update itself whenever the "enter" key is pressed on the page where you enter the fields. According to the xcode debugger (Breakpoints are life), the method does activate when the enter UIButton is pressed, the values are changed, but yet when shown on the results page, the supposed changes are gone, and instead they show they initial declaration values.
I've thought that perhaps the data is wiped when the new view is loaded... but I have no idea how to get around it.
Any help would be greatly appreciated!
"Width: \(SSDCalcs.width)") over the+operator ("Width: " + String(SSDCalcs.width)), and you don't have to explicitly use theStringconstructor