Post

Replies

Boosts

Views

Activity

Reply to SwiftUI picker selection
I find the solution ! 😇 I will honest, it is quit dirty but it is working ! Picker("Street desc.", selection: $patient.indexStreet) { ForEach (0 ..< NewPatient.typeStrt.count) { Text(NewPatient.typeStrt[$0]) } } .pickerStyle(SegmentedPickerStyle()) .onAppear(perform: { self.patient.typeStreet = NewPatient.typeStrt[self.patient.indexStreet] }) Regards and thank you for your help.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
Using publisher for an Array literal does not work as expected in almost all cases This is what I don't understand. How am I supposed to do it ? Also, the difference between this two way : @StateObject var newPatient = NewPatient() @ObservedObject var newPatient: NewPatient I'm exhausted of trying about this issue I'm facing for some time now. If you wouldn't mind explain it a bit easier, I'd be grateful. Thanks a lot again
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
Sorry, but it is completely unclear. Sorry for being so unclear. What is it which doesn't work? What do you mean by doesn't work? It does not compile? It compiles but causes runtime errors? It compiles and runs without errors but shows unexpected results? I just don't understand how to do it. Is it possible exchange about this subject elsewhere ? more easily to explain one another what it's going wrong ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
Sorry but it doesn't work. Do tou think I can use this : Picker("Number ext.", selection: $patient.indexStreetNbr) { ForEach (0 ..< NewPatient.typeStreetNbr.count) { Text(NewPatient.typeStreetNbr[$0]) } } .pickerStyle(SegmentedPickerStyle()) .onReceive([NewPatient.typeStreetNbr].publisher.first, perform: { _ in self.patient.checkAddr() }) And call a function I create in the class like so : func checkAddr() { switch indexStreet { case 0: self.typeStreet = "rue"     case 1: self.typeStreet = "boulevard"    case 2: self.typeStreet = "avenue"    case 3: self.typeStreet = "chemin" default: self.typeStreet = "rue" } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
Good evening, The value for typeStreetNumber and typeStreet in the JSON are arrays, and each array seems containing all possible values. Do you really need to send such all possible values to the API? The arrays are the possibilities the user can sent to the API. In this case, the API waits for ether one of the possibilities. "phoneNumber": [ "+33658893939", "0638495959", "0139384458" ] I just need to send the user selection in the JSON.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
my bad sorry. here you will have the APIRequests.swift file where are the class declaration. https://github.com/Paul-Rouillard/iOS-Healthsafe/tree/master/Healthsafe/src under src/view/SignUpClient.swift is the source code above.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
file - https://developer.apple.com/forums/content/attachment/123e8034-0ad1-474a-8702-7ded04790b5d I'd like to share the entire file, but it is to log for here ... This is why I liked my GitHub, where the project is. With all the code block, you have the overall file. You have the important elements of the class NewPatient, and the view SignUpClientView. SignUpClient is just a view controller depending on what the user click.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
In this function : func submit() {         guard let encoded = try? JSONEncoder().encode(patient) else {             print("Fail to encode newpatient")             return         }         let url = URL(string: "my/api/signin")!         var request = URLRequest(url: url)         request.setValue("application/json", forHTTPHeaderField: "Content-Type")         request.httpMethod = "POST"         request.httpBody = encoded         print(String(data: encoded, encoding: .utf8)!)         URLSession.shared.dataTask(with: url) { data, res, error in             guard let httpResponse = res as? HTTPURLResponse,                     (200...299).contains(httpResponse.statusCode) else {                     self.handleServerError(res)                 return             }             if let data = data {                 let decoder = JSONDecoder()                 if let json = try? decoder.decode(NewPatient.self, from: data) {                     print(json)                 }                 else {                     let dataString = String(decoding: data, as: UTF8.self)                     print("Invalid response \(dataString)")                 }             }         }.resume()     }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
Hi, Here is the entire view file: struct SignUpClient: View {     @State private var backPressed: Bool = false     @StateObject var newPatient = NewPatient()     var body: some View {         if backPressed {             return AnyView(PreSignUp())         } else {             return AnyView(SignUpClientView(backPressed: $backPressed, patient: newPatient))         }     } } struct SignUpClientView: View {     @Binding var backPressed: Bool     @State private var patientPersonnalInfo: Bool = true     @State private var patientAddressInfo: Bool = false     @State private var patientContactInfo: Bool = false     @State private var patientPasswdInfo: Bool = false     @ObservedObject var patient: NewPatient     var body: some View {         Button(action: {             self.backPressed = true             }) {             Image(systemName: "chevron.backward")                 .frame(alignment: .topLeading)                 .foregroundColor(.blue)             Text("Back")                 .frame(width: 325, alignment: .topLeading)         }             if patientPersonnalInfo {                 Group {                     Group {                         Form {                             Section {                                 TextField("First name", text: $patient.firstName)                                 TextField("Last Name", text: $patient.lastName)                                 TextField("Age", value: $patient.age, formatter: NumberFormatter())                                     .keyboardType(.numberPad)                             }                         }                     }                     Button (action: {                         self.patientPersonnalInfo = false                         self.patientAddressInfo = true                     }){                         Text("Suivant") //next                     }                 }.visibility(hidden: $patientPersonnalInfo)             } else if patientAddressInfo {                 Group {                     Group {                         Form {                             Section {                                     TextField("Building number", value: $patient.streetNumber, formatter: NumberFormatter())                                         .keyboardType(.numberPad) &#9;                                  Picker("Number ext.", selection: $patient.indexStreetNbr) {                                         ForEach (0 ..< NewPatient.typeStreetNbr.count) {                                             Text(NewPatient.typeStreetNbr[$0])                                         }                                     }.pickerStyle(SegmentedPickerStyle()) &#9;                                  Picker("Street desc.", selection: $patient.indexStreet) {                                         ForEach (0 ..< NewPatient.typeStrt.count) {                                             Text(NewPatient.typeStrt[$0])                                         }                                     }.pickerStyle(SegmentedPickerStyle())                                     TextField("Street name", text: $patient.street) &#9;                              HStack {                                     TextField("Post code", value: $patient.zipCode, formatter: NumberFormatter())                                        .frame(width: 100.0, height: 30)                                       .keyboardType(.numberPad)                                     Text(" | ")                                         .foregroundColor(Color.black)                                     TextField("City", text: $patient.city)                                         .frame(height: 30)                                 }                                 TextField("Country", text: $patient.country)                             }                         }                     }                 HStack {                     Button (action: {                         self.patientPersonnalInfo = true                         self.patientAddressInfo = false                     }){ &#9;                      Text("Précédent") //Previous                     }                     Button (action: {                         self.patientAddressInfo = false                         self.patientPasswdInfo = true                     }){                         Text("Suivant") //next                     }                 }             }.visibility(hidden: $patientAddressInfo)         } else if patientPasswdInfo {             Group {                 Group {                     Form {                         Section {                             SecureField("Password", text: $patient.password)                                 .modifier(FormTextFieldStyle())                             SecureField("Confirm passsword", text: $patient.confirmationPassword)                                 .modifier(FormTextFieldStyle())                         }                     }                 }                 HStack {                     Button(action: {                         self.patientPasswdInfo = false                         self.patientContactInfo = true                     }){                         Text("Précédent") //previous                             .modifier(ButtonFormStyleSecondary())                     }                     Button(action: {                         self.submit()                     }) {                         Text("Submit")                             .modifier(ButtonFormStyle())                     }                 }             }.visibility(hidden: $patientPasswdInfo)         }     }     func handleServerError(_ res: URLResponse?) {         print("ERROR: Status Code: \(res!): the status code MUST be between 200 and 299")     }     func submit() { // here under is the URLSession } You can also find the project on my GitHub https://github.com/Paul-Rouillard/iOS-Healthsafe, it might be easier to watch [ugly 😅] the code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to SwiftUI picker selection
Hello @OOPer, Thank for your quick reply. It doesn't fix my issue yet : typeStreetNumber: Binding<String>(transaction: SwiftUI.Transaction(plist: []), location: SwiftUI.LocationBox<SwiftUI.ObservableObjectLocation<Healthsafe.NewPatient, Swift.String>>, _value: "") typeStreet: Binding<String>(transaction: SwiftUI.Transaction(plist: []), location: SwiftUI.LocationBox<SwiftUI.ObservableObjectLocation<Healthsafe.NewPatient, Swift.String>>, _value: "") The thing is I need it to submit my JSON request. Here is what is needed: { &#9;"lastName": "Appleseed", &#9;"firstName": "John", &#9;"age": 20, &#9;"phoneNumber": [ &#9;&#9;"+33658893939", &#9;&#9;"0638495959", &#9;&#9;"0139384458" &#9;], &#9;"address": { &#9;&#9;"streetNumber": 3, &#9;&#9;"typeStreetNumber": [ &#9;&#9;&#9;"", &#9;&#9;&#9;"bis", &#9;&#9;&#9;"ter", &#9;&#9;&#9;"quater" &#9;&#9;], &#9;&#9;"typeStreet": [ &#9;&#9;&#9;"rue", &#9;&#9;&#9;"avenue", &#9;&#9;&#9;"boulevard", &#9;&#9;&#9;"chemin" &#9;&#9;], &#9;&#9;"street": "des paradis", &#9;&#9;"zipCode": 95170, &#9;&#9;"city": "Paris", &#9;&#9;"country": "France" &#9;}, &#9;"email": "test@gmail.com", &#9;"password": "oldboy", &#9;"confirmationPassword": "oldboy" } Unless for the typeStreet I can do a switch case where I assign the selected value directly to NewPatient.typeStreet 🤔 Thank you, P.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20