I have this simple class:
import Foundation
class Utility {
func somma(int1:String, int2:String) -> String {
let totale = (Int(int1) ?? 0) + (Int(int2) ?? 0)
let totale_Str = String(totale)
return totale_Str
}
}
and this simple view:
import SwiftUI
struct ContentView: View {
@State private var int1:String = "0"
@State private var int2:String = "0"
@State private var somma:String = ""
var body: some View {
VStack {
TextField("Intero 1", text: $int1)
TextField("Intero 2", text: $int2)
Text("\(somma)")
Button(action: {
self.somma = Utility.somma(self.int1, self.int2)
}) {
Text("Somma")
}
}
}
}
but in the line self.somma = Utility.somma(self.int1, self.int2) I have this error Instance member 'somma' cannot be used on type 'Utility'; did you mean to use a value of this type instead?
I have tried in different ways to eliminate the error without finding the solution.
How can I eliminate this error?