У меня есть этот простой класс:
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
}
}
и это простое представление:
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")
}
}
}
}
, но в строке self.somma = Utility.somma(self.int1, self.int2)
У меня есть эта ошибка Instance member 'somma' cannot be used on type 'Utility'; did you mean to use a value of this type instead?
Я пытался вразличные способы устранения ошибки без поиска решения. Как я могу устранить эту ошибку?