I am trying to get the data from my arrays
supposed I have data like this:
[cobaCobaWS.SpecData(lbl1: 1, lbl2: 2, lbl3: 3, lbl4: 4), cobaCobaWS.SpecData(lbl1: 5, lbl2: 6, lbl3: 7, lbl4: 8)]
I'm trying to use for loop to access each array in there but I can't. take a look at my code below:
struct SpecData {
var lbl1: Int
var lbl2: Int
var lbl3: Int
var lbl4: Int
}
var txtFieldArray = [SpecData]()
for arr in txtFieldArray {
coreNumber = Double(txtFieldArray[0].lbl1)
machineNumber = txtFieldArray[0].lbl2
userNumber = txtFieldArray[0].lbl3
rdsNumber = txtFieldArray[0].lbl4
}
The number of arrays will be dynamic because the user can input how many numbers they want.
I wish I can put the arr inside like this:
coreNumber = Double(txtFieldArray[arr].lbl1)
machineNumber = txtFieldArray[arr].lbl2
userNumber = txtFieldArray[arr].lbl3
rdsNumber = txtFieldArray[arr].lbl4
I want to put those number into another function afterward. So I want to be able to read every array in my array but I can't i'm thinking maybe because my array from struct? can anyone help me here?
Thankyou in advance
lbl1which in your sample is first 1 then 5, what do you want to do with 1 and 5?functionand will calculate them for a result. How do I do that?coreNumber,machineNumber,userNumber, andrdsNumber. Those will be the temporary variables before getting into the calculating functions. maybe I can make a flow like this: [[array],[array]] --> get value from each array and put into variables --> calculate in a function --> output / resultfor arr in txtFieldArray { someFunc(core: Double(arr.lbl1), machine: arr.lbl2, user: arr.lbl3, rds: arr.lbl4) }