HomeiOS Developmenttake worth from struct ios swift at school

take worth from struct ios swift at school


Struct :

declare three variables

 struct UserInfo : Identifiable {

    enum Ground: String, Identifiable, CaseIterable {
        var id: Self {self}
        case firstfloor
        case secondfloor
    }

    enum Carry: String, Identifiable, CaseIterable {
        var id: Self {self}
        case sure
        case no
    }

    var pickuplocation:String
    var pickupfloor: Ground
    var pickuplift: Carry
}

extension UserInfo {
    static var empty = UserInfo(pickuplocation: "",pickupfloor: .firstfloor, pickuplift: .no)
}

class :

utilizing person variable state modifications and retains in struct variables

remaining class UserInputViewModel: ObservableObject {
    @Revealed var person: UserInfo = .empty

func save() {

        //Process object is coming from core information entities
        let userchoices = Person(context: CoreDataManager.shared.viewContext)
        userchoices.pickup_address = person.pickuplocation
        userchoices.pickup_floor = person.pickupfloor.rawValue
        userchoices.pickup_lift = person.pickuplift.rawValue
  }
}

View :

person fills the shape and retailer the values in struct

    struct HomeShiftingView: View {
        
        @StateObject non-public var userinputvm = UserInputViewModel()
    
        var physique: some View {
            
            Part {
                
                TextField("pickuplocation", textual content: $userinputvm.person.pickuplocation)
                    .textContentType(.namePrefix)

Picker("Choose Ground", choice: $userinputvm.person.pickupfloor) {
                    ForEach(UserInfo.Ground.allCases, id: .self) { merchandise in
                        Textual content(merchandise.rawValue.uppercased())
                    }
}
Picker("Carry", choice: $userinputvm.person.pickuplift) {
                    ForEach(UserInfo.Carry.allCases, id: .self) { merchandise in
                        Textual content(merchandise.rawValue.uppercased())
                    }
                }


        }
      }
    }

Now i would like the struct variable values(pickuplocation, pickupfloor, pickuplift ) in UserInputViewModel class

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments