Post

Replies

Boosts

Views

Activity

Having issues with .sheet and .dismiss()
Hello When I dismiss my .sheet it is very slow and sometimes it doesn't work .sheet(isPresented: $myViewi) {         MyView()       } @Environment(\.presentationMode) var presentationMode .navigationBarItems(trailing:           Button(action: {    presentationMode.wrappedValue.dismiss()                                         }) {                                             Image(systemName: "xmark").font(.title).foregroundColor(.blue)                                         }                 ) How do I fix it? Thank You
2
0
920
Dec ’20
Change Placeholder to a String in a CustomTextField
Hello How do I make the default placeholder of a CustomTextField (that has a double binding) a string (onAppear) When I run the app on the TextField I see 0 instead of "Input" Code: import SwiftUI struct BMIView: View {     var currencyFormatter: NumberFormatter {         let formatter = NumberFormatter()         formatter.locale = .current         formatter.numberStyle = .decimal         return formatter     }     @State private var height: Double?         var body: some View {         NavigationView{             Form{                 Section(header: Text("Enter your height in cm")){                     DecimalTextField("Input", value: $height.bound, formatter: currencyFormatter)                }             }             .navigationBarTitle("BMI")         }     } } struct DecimalTextField: UIViewRepresentable {     private var placeholder: String     @Binding var value: Double     private var formatter: NumberFormatter     init(_ placeholder: String,          value: Binding<Double>,          formatter: NumberFormatter ) {         self.placeholder = placeholder         self._value = value         self.formatter = formatter     }     func makeUIView(context: Context) -> UITextField {         let textfield = UITextField()         textfield.keyboardType = .decimalPad         textfield.delegate = context.coordinator         textfield.placeholder = placeholder         textfield.text = formatter.string(for: value) ?? placeholder         textfield.textAlignment = .left         let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: textfield.frame.size.width, height: 44)) let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(textfield.doneButtonTapped(button:)))         let space = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace,                                     target: nil,action: nil)         toolBar.setItems([space, doneButton], animated: true)         textfield.inputAccessoryView = toolBar         return textfield     }     func updateUIView(_ uiView: UITextField, context: Context) {         // Do nothing, needed for protocol     }     func makeCoordinator() -> Coordinator {         Coordinator(self)     }     class Coordinator: NSObject, UITextFieldDelegate {         var parent: DecimalTextField         init(_ textField: DecimalTextField) {             self.parent = textField         }         func textField(_ textField: UITextField,                        shouldChangeCharactersIn range: NSRange,                        replacementString string: String) -> Bool {             // Allow only numbers and decimal characters             let isNumber = CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: string))             let withDecimal = (                 string == NumberFormatter().decimalSeparator &&                     textField.text?.contains(string) == false             )             if isNumber || withDecimal,                 let currentValue = textField.text as NSString?             {                 // Update Value                 let proposedValue = currentValue.replacingCharacters(in: range, with: string) as String                 let decimalFormatter = NumberFormatter()                 decimalFormatter.locale = Locale.current                 decimalFormatter.numberStyle = .decimal                 // Try currency formatter then Decimal formatrer                 let number = self.parent.formatter.number(from: proposedValue) ?? decimalFormatter.number(from: proposedValue) ?? 0.0                 // Set Value                 let double = number.doubleValue                 self.parent.value = double             }             return isNumber || withDecimal         }         func textFieldDidEndEditing(_ textField: UITextField,                                     reason: UITextField.DidEndEditingReason) {             // Format value with formatter at End Editing             textField.text = self.parent.formatter.string(for: self.parent.value)         }     } } // MARK: extension for done button extension  UITextField{     @objc func doneButtonTapped(button:UIBarButtonItem) -> Void {         self.resignFirstResponder()     } } extension Optional where Wrapped == Double {          var _bound: Double? {         get{             return self                      }         set{             self = newValue                      }     }          var bound: Double {         get{             return _bound ?? 0         }         set {             _bound = newValue         }     } } The problem might be at line 243 (I found the struct DecimalTextField on the internet) Thank you for your time
2
0
1.6k
Dec ’20
Instance member 'deci' cannot be used on type 'BMIView'; did you mean to use a value of this type instead?
Hello How di i fix the error at line 16: I nstance member 'deci' cannot be used on type 'BMIView'; did you mean to use a value of this type instead?  import SwiftUI  struct BMIView: View {           @State var deci = "3"           var numberFormatter: NumberFormatter = {          let nf = NumberFormatter()          nf.locale = Locale.current          nf.numberStyle = .decimal          nf.maximumFractionDigits = Int(deci) ?? 0          return nf      }()            @State private var height = ""      @State private var weight = ""      @Environment(\.presentationMode) var presentationMode            var inputAfterConvertions: Double {          //Use NumberFormatter to read numeric values          let hh = numberFormatter.number(from: height)?.doubleValue ?? 0 //<-          let ww  = numberFormatter.number(from: weight)?.doubleValue ?? 0 //<-          var ris: Double = 0          if hh > 0 && ww > 0{              ris = (ww / (hh * hh)) * 10000              return ris          }          return 0      }           var body: some View {          NavigationView{              Form{                  Section(header: Text("Enter your height in cm")){                      TextField("Input",text: $height)                          .keyboardType(.decimalPad)                  }                  Section(header: Text("Enter your Weight in kg")){                      TextField("Input",text: $weight)                          .keyboardType(.decimalPad)                  }                  Section(header: Text("Check result")){                      Text("\(inputAfterConvertions as NSNumber, formatter: numberFormatter)") //<-                  }              }              .navigationTitle("BMI")          }      }  } Thank you
2
0
849
Dec ’20
'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately.
Hello I'm trying to detect objects with CreateML, but it gives me this warning that I think is breaking my app: 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately. The classfier.model is a CreatML model that has some images Have any ideas on how to fix it? import UIKit import AVKit import Vision import CoreML class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { &#9;&#9; &#9;&#9;let identifierLabel: UILabel = { &#9;&#9;&#9;&#9;let label = UILabel() &#9;&#9;&#9;&#9;label.backgroundColor = .white &#9;&#9;&#9;&#9;label.textAlignment = .center &#9;&#9;&#9;&#9;label.translatesAutoresizingMaskIntoConstraints = false &#9;&#9;&#9;&#9;return label &#9;&#9;}() &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;// here is where we start up the camera &#9;&#9;&#9;&#9;// for more details visit: https://www.letsbuildthatapp.com/course_video?id=1252 &#9;&#9;&#9;&#9;let captureSession = AVCaptureSession() &#9;&#9;&#9;&#9;captureSession.sessionPreset = .photo &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;guard let captureDevice = AVCaptureDevice.default(for: .video) else { return } &#9;&#9;&#9;&#9;guard let input = try? AVCaptureDeviceInput(device: captureDevice) else { return } &#9;&#9;&#9;&#9;captureSession.addInput(input) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;captureSession.startRunning() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) &#9;&#9;&#9;&#9;view.layer.addSublayer(previewLayer) &#9;&#9;&#9;&#9;previewLayer.frame = view.frame &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;let dataOutput = AVCaptureVideoDataOutput() &#9;&#9;&#9;&#9;dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue")) &#9;&#9;&#9;&#9;captureSession.addOutput(dataOutput) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;setupIdentifierConfidenceLabel() &#9;&#9;} &#9;&#9; &#9;&#9;fileprivate func setupIdentifierConfidenceLabel() { &#9;&#9;&#9;&#9;view.addSubview(identifierLabel) &#9;&#9;&#9;&#9;identifierLabel.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -32).isActive = true &#9;&#9;&#9;&#9;identifierLabel.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true &#9;&#9;&#9;&#9;identifierLabel.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true &#9;&#9;&#9;&#9;identifierLabel.heightAnchor.constraint(equalToConstant: 50).isActive = true &#9;&#9;} &#9;&#9; &#9;&#9;func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { //&#9;&#9;&#9;&#9;print("Camera was able to capture a frame:", Date()) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;// !!!Important &#9;&#9;&#9;&#9;// make sure to go download the models at https://developer.apple.com/machine-learning/ scroll to the bottom &#9;&#9;&#9;&#9;guard let model = try? VNCoreMLModel(for: Classfier().model) else { return } &#9;&#9;&#9;&#9;let request = VNCoreMLRequest(model: model) { (finishedReq, err) in &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;//perhaps check the err &#9;&#9;&#9;&#9;&#9;&#9; //&#9;&#9;&#9;&#9;&#9;&#9;print(finishedReq.results) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;guard let results = finishedReq.results as? [VNClassificationObservation] else { return } &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;guard let firstObservation = results.first else { return } &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;print(firstObservation.identifier, firstObservation.confidence) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;DispatchQueue.main.async { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.identifierLabel.text = "\(firstObservation.identifier) \(firstObservation.confidence * 100)" &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;try? VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:]).perform([request]) &#9;&#9;} } Thank you for your time
2
1
4.9k
Jan ’21
Cannot use instance member 'name' within property initializer; property initializers run before 'self' is available
Hello Why does it give me an error when I pass 'name' at line 3? struct OtherView: View { @State private var name: String = "" @ObservedObject var use = Use(name: name) var body: some View{ VStack{ } } } class Use: ObservableObject { @Published var name: String init(name: String) { self.name = name } } Thank you
2
0
4.4k
Apr ’21
Filter in ForEach SwiftUI
Hello I implemented the filter function in my ForEach loop, and it works just with the valori property but not with the date property , is there a way to let it filter also the date? I tried to remove the dateFormatter but it didn't work. Here is the code import SwiftUI let dateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateStyle = .medium return formatter }() struct Test4: View { @State private var text: String = "" var body: some View { NavigationView{ if !lifetimes.isEmpty{ List{ Section(header: Text("")){ TextField("Search", text: $text) } Section(header: Text("")){ ForEach(lifetimes.filter { text.isEmpty || "\($0)".contains(text) }, id: \.id){ lifetimeInputs in HStack{ Text("\(lifetimeInputs.valori, specifier: "%.0f")") Spacer() Text("\(dateFormatter.string(from: lifetimeInputs.date))") } } } } .listStyle(InsetGroupedListStyle()) .navigationTitle("All History") } else{ VStack{ Text("No Data") .font(.largeTitle) .fontWeight(.semibold) .foregroundColor(.secondary) } .padding(.bottom) .navigationTitle("All History") } } } } struct LifetimeInputsModel: Identifiable { var id = UUID() var valori: Double var date: Date } var lifetimes: [LifetimeInputsModel] = [ LifetimeInputsModel(valori: 300, date: Date()), LifetimeInputsModel(valori: 200, date: Date() + 86400) ] Thank you
2
0
2.9k
Jun ’21
HealthKit (delete function in SwiftUI)
Hello I am trying to save some data in the Health App from my app, and it is working, the problem is that when I delete that data (already saved) from my app (using the deleteFromHealthKit function) the data is not deleted from the health app. How can I fix this? Here is the code: import SwiftUI import HealthKit struct ContentView: View { init() { //-------- let healthStore = HKHealthStore() let allTypes = Set([HKObjectType.quantityType(forIdentifier: .dietaryWater)!]) healthStore.requestAuthorization(toShare: allTypes, read: allTypes) { (success, error) in if !success { print("success") } } } func fetchHealthData(date: Date, ml: Double) -> Void { let healthStore = HKHealthStore() let quantityType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.dietaryWater) let waterConsumed = HKQuantitySample.init(type: quantityType!, quantity: .init(unit: HKUnit.literUnit(with: .milli), doubleValue: ml), start: date, end: date) healthStore.save(waterConsumed) { success, error in if (error != nil) { print("Error: \(String(describing: error))") } if success { print("Saved: \(success)") } } } @State var water: [Water] = [] @State private var value: Double = 0 func deleteFromHealthKit(date: Date, ml: Double) { let healthStore = HKHealthStore() let quantityType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.dietaryWater) let waterConsumed = HKQuantitySample.init(type: quantityType!, quantity: .init(unit: HKUnit.literUnit(with: .milli), doubleValue: ml), start: date, end: date) healthStore.delete(waterConsumed) { success, error in if (error != nil) { print("Error: \(String(describing: error))") } if success { print("Saved: \(success)") } } } var body: some View { NavigationView{ VStack{ Text("Value: \(value)") .padding() HStack{ Text("100 ml") .onTapGesture { value = 100 } Text("200 ml") .onTapGesture { value = 200 } } Button("Add"){ water.append(Water(value: value, date: Date())) fetchHealthData(date: Date(), ml: value) }.disabled(value == 0 ? true : false) .padding() List{ ForEach(0..<water.count, id: \.self){ i in HStack{ Text("\(water[i].value)") Text("\(water[i].date)") } .onTapGesture { deleteFromHealthKit(date: water[i].date, ml: water[i].value) water.remove(at: i) } } } } } } } struct Water: Identifiable { var id = UUID() var value: Double var date: Date } Thank you
2
0
1.6k
Jun ’21
SwiftUI & Layout API. Extra trailing closure passed in call
Hello I'm trying to compose a layout using the Layout API. I have already written the code for both the Layout Stack I want to use and the view I am using it in, however I am getting an "Extra trailing closure passed in call" error in the view I am using the Stack in. Here is the code: import SwiftUI struct StairsView: View { var body: some View { Group{ MyStairsStack{ Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") } } } } struct MyStairsStack: Layout{ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout Void) -> CGSize { return .init(width: proposal.width ?? 0, height: proposal.height ?? 0) } func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout Void) { guard !subviews.isEmpty else { return } let viewSize = maxSize(subViews: subviews) var origin = bounds.origin let maxWidth = bounds.width subviews.forEach { view in if (origin.x + (viewSize.width + 10) >= maxWidth){ origin.x = bounds.origin.x } view.place(at: origin, proposal: proposal) origin.x += (viewSize.width + 10) origin.y += (viewSize.height + 10) } } private func maxSize(subViews: Subviews) -> CGSize{ subViews.map { $0.sizeThatFits(.unspecified) }.reduce(.zero) { currentMax, subviewSize in CGSize( width: max(currentMax.width, subviewSize.width), height: max(currentMax.height, subviewSize.height)) } } } The error is at line 5 Thank You for your time
2
0
1.7k
Jun ’22
List in ForEach SwiftUI
Hello I don't know why but when I put a List before my ForEach loop, all the text disappears Code: // import SwiftUI struct SearchDetailView: View {     var sf: SF     var body: some View {         ScrollView{             ForEach(sf.items, id: \.self) { item in                 HStack{                 Image(systemName: item)                 Text(item)                 }             }             .navigationTitle(sf.title)         }     } } Thank you for your time
1
0
1.7k
Dec ’20
Convert with Measurement SwiftUI
Hello I'm using Measurement(...) to convert watts to femtowatts, but if I convert 1 watts to femtowatts I get 999999999999999.9 instead of 1e+15, I have no idea on how to fix it, any help or ideas, here is the code : import SwiftUI struct PowerView: View { &#9;&#9; &#9;&#9;@State private var inputValue = "" &#9;&#9; &#9;&#9; let inputUnits = [ &#9;&#9;&#9;&#9;"watts", &#9;&#9;&#9;&#9;"femtowatts" &#9;&#9;] &#9;&#9;let outputUnits = [ &#9;&#9;&#9;&#9;"watts", &#9;&#9;&#9;&#9;"femtowatts" &#9; ] &#9;&#9;@State private var inputUnitValue = 0 &#9;&#9; &#9;&#9;@State private var outputUnitValue = 1 &#9;&#9; &#9;&#9;var after: String{ &#9;&#9;&#9;&#9;var input = Measurement(value: 0, unit: UnitPower.watts) &#9;&#9;&#9;&#9;var output: String = "" &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;switch inputUnits[inputUnitValue] { &#9;&#9;&#9;&#9;case "watts": input = Measurement(value: Double(inputValue) ?? 0, unit: UnitPower.watts) &#9;&#9;&#9;&#9;case "femtowatts": input = Measurement(value: Double(inputValue) ?? 0, unit: UnitPower.femtowatts) &#9;&#9;&#9;&#9;default: input = Measurement(value: Double(inputValue) ?? 0, unit: UnitPower.watts) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;switch outputUnits[outputUnitValue] { &#9;&#9;&#9;&#9;case "watts": output = String(describing: input.converted(to: UnitPower.watts)) &#9;&#9;&#9;&#9;case "femtowatts": output = String(describing: input.converted(to: UnitPower.femtowatts)) &#9;&#9;&#9;&#9;default: output = String(describing: input.converted(to: UnitPower.watts)) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;return output &#9;&#9;} &#9;&#9; &#9;&#9;&#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;NavigationView{ &#9;&#9;&#9;&#9;&#9;&#9;Form{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Enter your Input value")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;TextField("Have a goal?", text: $inputValue) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Input")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Picker("Input values", selection: $inputUnitValue){&#9;&#9;&#9;&#9;&#9;&#9; &#9; ForEach(0..<inputUnits.count){ item in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(inputUnits[item]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Output")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Picker("Output values", selection: $outputUnitValue){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(0..<outputUnits.count){ item in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(outputUnits[item]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Check your Output value")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("\(after)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.navigationBarTitle("Pressure") &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; } Thank you for your time (Is there a way to use NumberFormatter with the computed String)
1
0
1.3k
Dec ’20
Cannot convert value of type 'String' to type 'NSNumber' in coercion
Hello I'm trying to use a formatter on a String but it is giving me this error Cannot convert value of type 'String' to type 'NSNumber' in coercion, is there a simple and short way to fix it? Here is the code import SwiftUI struct TemperatureView: View { &#9;&#9; &#9;&#9;@State private var inputValue = "" &#9;&#9; &#9;&#9; let inputUnits = [ &#9;&#9;&#9;&#9;"celsius [°C]", &#9;&#9;&#9;&#9;"kelvin [K]", &#9;&#9;&#9;&#9;"fahrenheit [°F]" &#9;&#9;] &#9;&#9;let outputUnits = [ &#9;&#9;&#9;&#9;"celsius [°C]", &#9;&#9;&#9;&#9;"kelvin [K]", &#9;&#9;&#9;&#9;"fahrenheit [°F]" &#9; ] &#9;&#9;@State private var inputUnitValue = 0 &#9;&#9; &#9;&#9;@State private var outputUnitValue = 1 &#9;&#9; &#9;&#9; &#9;&#9;var after: String{ &#9;&#9;&#9;&#9;var input: Measurement<UnitTemperature> &#9;&#9;&#9;&#9;var output: String = "" &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;switch inputUnits[inputUnitValue] { &#9;&#9;&#9;&#9;case "celsius [°C]": input = Measurement(value: Double(inputValue) ?? 0, unit: .celsius) &#9;&#9;&#9;&#9;case "kelvin [K]": input = Measurement(value: Double(inputValue) ?? 0, unit: .kelvin) &#9;&#9;&#9;&#9;case "fahrenheit [°F]": input = Measurement(value: Double(inputValue) ?? 0, unit: .fahrenheit) &#9;&#9;&#9;&#9;default: input = Measurement(value: Double(inputValue) ?? 0, unit: UnitTemperature.celsius) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;switch outputUnits[outputUnitValue] { &#9;&#9;&#9;&#9;case "celsius [°C]": output = outputFormatter.string(from: input.converted(to: .celsius)) &#9;&#9;&#9;&#9;case "kelvin [K]": output = outputFormatter.string(from: input.converted(to: .kelvin)) &#9;&#9;&#9;&#9;case "fahrenheit [°F]": output = outputFormatter.string(from: input.converted(to: .fahrenheit)) &#9;&#9;&#9;&#9;default: output = String(describing: input.converted(to: UnitTemperature.celsius)) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;return output &#9;&#9;} &#9;&#9; &#9;&#9;@Environment(\.presentationMode) var presentationMode &#9;&#9;let outputFormatter: MeasurementFormatter = { &#9;&#9;&#9;&#9;&#9;&#9;let nf = NumberFormatter() &#9;&#9;&#9;&#9;&#9;&#9;nf.locale = Locale.current &#9;&#9;&#9;&#9;&#9;&#9;nf.usesSignificantDigits = true &#9;&#9;&#9;&#9;&#9;&#9;let mf = MeasurementFormatter() &#9;&#9;&#9;&#9;&#9;&#9;mf.numberFormatter = nf &#9;&#9;&#9;&#9;&#9;&#9;mf.unitOptions = .providedUnit &#9;&#9;&#9;&#9;&#9;&#9;return mf &#9;&#9;&#9;&#9;}() &#9;&#9;&#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;NavigationView{ &#9;&#9;&#9;&#9;&#9;&#9;Form{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Enter your Input value")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;TextField("Have a goal?", text: $inputValue) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.keyboardType(.decimalPad) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Input")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Picker("Input values", selection: $inputUnitValue){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(0..<inputUnits.count){ item in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(inputUnits[item]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Output")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Picker("Output values", selection: $outputUnitValue){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(0..<outputUnits.count){ item in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(outputUnits[item]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Check your Output value")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("\(after as NSNumber, formatter: outputFormatter)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.navigationBarTitle("Temperature") &#9;&#9;&#9;&#9;&#9;&#9;.navigationBarItems(trailing: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;presentationMode.wrappedValue.dismiss() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Image(systemName: "xmark").font(.title).foregroundColor(.blue) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; } The error is at line 80/81 Thank you for your time
1
0
3k
Jan ’21