ContentView
can’t see CalculsIL
because that function doesn’t exist in File
. What does exist is a class called Program
that has a method called CalculsIL
.
Do this:
- add
Program
to yourContentView
as an@StateObject
so you can access it:
@StateObject var program = Program()
- modify
Program.CalculsIL
to this:
func CalculsIL(indexD: Int, indexV: Int, indexI: Int) -> Double {
//get ListD, ListV and ListI from your global variables
let listD = Diaphs
let listV = Vitesses
let listI = ISOs
//and perform your calculations
}
or, if you want to be able to pass in alternate arrays for the ListD
, ListV
, and ListI
parameters, you could use this:
func CalculsIL(listD: [String] = Diaphs, indexD: Int,
listV: [String] = Vitesses, indexV: Int,
listI: [String] = ISOs, indexI: Int) -> Double {
//perform your calculations
}
- access the
CalculsIL
function like this:
Text("IL :\(program.CalculsIL(indexD: indexView1, indexV: indexView2, indexI: indexView3))")
That will make your current code work, although I would probably recommend rethinking how you have everything set up. Using global variables like Diaphs
, Vitesses
and ISOs
isn’t exactly a best practice. I would think about making them properties of your Program
class instead.