如何以天、小时或秒为单位转换用户号码 swiftUI



我是 Swift UI 的新手,我正在尝试转换我从文本归档和选择器中获得的值,以在几天、几分钟或几秒钟内转换它,这是来自教程 100 天使用 swiftUI 我很迷路,因为我不明白如果有人可以帮助我并解释一下代码,该如何操作, 谢谢。

这是我的代码


struct ContentView: View {
@State private var convertir  = 2
let tipConverciones = ["segundos","minutos","horas","dias"]
@State private var convertirselection  = 2
let convertirA = ["segundos","minutos","horas","dias"]
@State var cantidadconvertir = ""
var convertidormetodo: Double{
//Funcion que calcula el total de personas
let conteocantidad = Double(cantidadconvertir) ?? 0
let convertirSeleccion = (convertirA)

return 0
}
var body: some View {
NavigationView{
Form {
Section (header: Text("Convertir")) {
Picker   ("Convertir de", selection: $convertir){
ForEach(0 ..< tipConverciones.count){
Text("(self.tipConverciones[$0])")
}//ForEach
}//Picker
.pickerStyle(SegmentedPickerStyle())
}//Seccion3
Section (header: Text("Ingresar Cantidad a convertir"))  {
TextField("Ingresa la cuentidad", text: $cantidadconvertir)
.keyboardType(.decimalPad)
}//seccion5
Section (header: Text("Convertir a")) {
Picker   ("Convertir de", selection: $convertir){
ForEach(0 ..< tipConverciones.count){
Text("(self.tipConverciones[$0])")
}//ForEach
}//Picker
.pickerStyle(SegmentedPickerStyle())
}//Seccion4

Section{//seccion 4
Text("La cantidad convertida es: (convertidormetodo)")
}//seccion 4
}//Form
.navigationBarTitle("Convertidor SwiftUI")
}//Navigation View
}//body
}//view
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

用户输入和所需输出的示例会有所帮助。但我认为您要查找的是日期格式化程序或数字格式化程序:

https://developer.apple.com/documentation/foundation/dateformatter https://developer.apple.com/documentation/foundation/numberformatter