спасибо Дэниэл Т. Я действительно ценю. Я даю вам свой код, чтобы понять, как реализовать и когда поставить возврат
@IBAction func calcolaPressed(_ sender: UIButton) {
let oremese = ["Gennaio": 184, "Febbraio": 160, "Marzo": 176, "Aprile": 176, "Maggio": 168, "Giugno": 176, "Luglio": 184, "Agosto": 168, "Settembre": 176, "Ottobre": 176, "Novembre": 168, "Dicembre": 184]
func trat(income: UITextField, hours: UITextField, picker: UIPickerView, oremese: [Float]) -> Float {
let redditonetto = Float(reddito.text!) ?? 0
let totaleore = Float(ore.text!) ?? 0
let month = picker.selectedRow(inComponent: 0)
guard 0 <= month && month < 12 else { return 0 }
//da reddito 0 a 1247.73
let calcA = redditonetto / 168;
let calcB = totaleore * calcA;
let calcC = calcB * 0.80;
let calcD = calcC - (calcC * 0.0584)
let trat = calcC * 0.0584
let myDoubleC = calcC
let doubleStrC = (String(format: "%.2f", myDoubleC))
let myDoubleD = calcD
let doubleStrD = (String(format: "%.2f", myDoubleD))
let myDoubleT = trat
let doubleStrT = (String(format: "%.2f", myDoubleT))
//da reddito 1247.74 a 2159.49
let calcB2 = totaleore * 5.67;
let calcC2 = calcB2 - (calcB2 * 0.0584)
let trat2 = calcC2 * 0.0584
let myDoubleB2 = calcB2
let doubleStrB2 = (String(format: "%.2f", myDoubleB2))
let myDoubleC2 = calcC2
let doubleStrC2 = (String(format: "%.2f", myDoubleC2))
let myDoubleT2 = trat2
let doubleStrT2 = (String(format: "%.2f", myDoubleT2))
//da reddito da 2159.50 a 30000
let calcB3 = totaleore * 7.14;
let calcC3 = calcB3 - (calcB3 * 0.0584)
let trat3 = calcC3 * 0.0584
let myDoubleB3 = calcB3
let doubleStrB3 = (String(format: "%.2f", myDoubleB3))
let myDoubleC3 = calcC3
let doubleStrC3 = (String(format: "%.2f", myDoubleC3))
let myDoubleT3 = trat3
let doubleStrT3 = (String(format: "%.2f", myDoubleT3))
if redditonetto >= 0 && redditonetto <= 1247.73 {
nettocig.text = "€ " + "\(doubleStrD)"
indennitalorda.text = "€ " + "\(doubleStrC)"
trattenute.text = "€ " + "\(doubleStrT)"
}
else if redditonetto >= 1247.74 && redditonetto <= 2159.49 {
nettocig.text = "€ " + "\(doubleStrC2)"
indennitalorda.text = "€ " + "\(doubleStrB2)"
trattenute.text = "€ " + "\(doubleStrT2)"
} else {
nettocig.text = "€ " + "\(doubleStrC3)"
indennitalorda.text = "€ " + "\(doubleStrB3)"
trattenute.text = "€ " + "\(doubleStrT3)"
}
if redditonetto >= 0 && redditonetto <= 2159.49{
massimale.text = "€ 998.18"
progressBar.progress = 0.7
}
else { massimale.text = "€ 1199.72"
progressBar.progress = 1
}
}
}
}