Post

Replies

Boosts

Views

Activity

Reply to Connect @State variables to a Codable struct
I was able to do this with @Published. class User: ObservableObject, Codable {     enum CodingKeys: CodingKey {         case disabled     }     init() { }     required init(from decoder: Decoder) throws {         let container = try decoder.container(keyedBy: CodingKeys.self)         disabled = try container.decode(Bool.self, forKey: .disabled)     }     func encode(to encoder: Encoder) throws {         var container = encoder.container(keyedBy: CodingKeys.self)         try container.encode(disabled, forKey: .disabled)     }     @Published var disabled: Bool = false }
Mar ’22
Reply to Converting Swift to JSON
@Claude31 I'm able to get person_details on the object but seems like it's not under the 'household'. The 'person_details' should be under 'household'. I have a strong suspicion it's something I need to do inside let order =. This is what I have so far: struct Order: Encodable {     let household: Eligibility     let person_details: PersonDetails } let order = Order(household: Eligibility(residence: "PA", hhmembers: 1, receivingBen: [], unhoused: false, utilityType: ["Peco"], residenceType: "other", propertyTax: false, homeRepairs: false, fileLastTax: false, heatRepairs: false, receivingMax: ["cip": false]), person_details: PersonDetails(age: 19)) As mentioned, it's not in the household object which I'm trying to get it under. {   "household" : {     "region" : "PA",     "residence_type" : "other",     "at_risk_of_homelessness" : false,     "property_tax_past_due" : false,     "utility_providers" : [       "Peco"     ],     "home_needs_repairs" : false,     "filed_previous_year_tax_return" : false,     "household_size" : 1,     "receiving_benefits" : [     ],     "heating_system_needs_repairs" : false,     "received_maximum_benefit" : {       "cip" : false     }   },   "person_details" : {     "age" : 19   } } It should look like this: (note the square brackets in person_details too) `"household": {     "region": "PA",     "household_size": 1,     "receiving_benefits": [     ],     "energy_crisis": false,     "utility_providers": [         "peco"     ],     "residence_type": "other",     "property_tax_past_due": false,     "home_needs_repairs": false,     "filed_previous_year_tax_return": false,     "heating_system_needs_repairs": false,     "at_risk_of_homelessness": false,     "received_maximum_benefit": {         "cip": false     },     "person_details": [         {             "age": 18,             "marital_status": "single",             "minimum_employment_over_extended_period": false,             "work_status": "recent_loss",             "pregnant": false,             "attending_school": false,             "disabled": false         }     ],`
Mar ’22
Reply to Make if/else statements work properly in Presented Sheet
Hey @Claude31, thanks for responding! Since I'm unable to edit my question here's some further details. The code I have for the button is this, where once the button is selected, under action: in the button, you'll see the two functions that when initiate when button is clicked, Button(action: {mspEligibility(); ssdiEligibility(); Let me know if this is not the button code you're referring too ZStack {                   VStack {                         Button(action: {mspEligibility(); ssdiEligibility(); ssiEligibility(); mspEligibility2(); PAzipcode(); mspEligibility3();                             self.isOpen = true                             print(elig)                             print(ssdiElig)                             print(disabled)                                                     }, label: {                                                         Text("View Results")                                                  }).sheet(isPresented: $isOpen, content: { So, basically in the function Also, I took your suggestion with using parenthesis in the mspEligibility() function itself and more clearer explicit messages. Here are a couple screen shots on a URL: https://imgur.com/a/mbONe0C . The first is when I select the disability toggle, and the 2nd is when I select the View Results button, which shows Not Eligible for SSDI when as you can see it's printed out Eligible from the function. Then when I go back and plug true value for both Disability and Medicare, and select the View Results button: they both show as eligible (also screen shot on the URL). Please let me know if I'm missing anything else from this post or my initial post, I believe I have everything that's needed. Thanks!
Feb ’22
Reply to Using a variable from a Function
@Claude31 Thank you for that. Initially I was looking for a basic example to put into my app but maybe it's me not being able to understand it fully. Let me show you my full code for better transparency. At the Bottom and outside of my ApplicationView(), I have a function below which is passing through some parameters that Prints in the console.              var ssdi = 0     func ssdiEligibility() {         if disabled == true && income <= 803 {             print("SSDI Eligible")             ssdi += 1         } else if ssdiBen == true || ssiBen == true {             print("")         } else {             print("")         }     } Now, Back to the ApplicationsView(), I have a button which once selected (below), will run that function and also hop to another view called ResultsView.                 ZStack {                     VStack {                         Button(action: {ssdiEligibility()                             self.isOpen = true                         }, label: {                             Text("View Results")                         }).sheet(isPresented: $isOpen, content: {                             ResultsView()                         })                     }                 } What I'd like to happen is once the View Results button is selected and the ResultsView() populates along with initiating the ssdiEligibility() function, I'd like to show "Eligible for SSDI" on the View itself as Text and not just printing in the console. So, my concept was, if I create a variable var ssdi = 0 in the function and add '1' if the first condition in the function is true, and using the button View Results button to also calculate if ssdi > 0 then write as Text on the Results View that "They are Eligible for SSDI" Any thoughts?
Feb ’22