ios – RealmSwift Picker Record Not Permitting Number of Introduced Values

0
17


I’ve a RealmSwift app I am messing round with, and having bother with a Picker deciding on any of the thing values current.

Primary Objects:

class Occasion: Object, ObjectKeyIdentifiable {
    @Persevered(primaryKey: true) var _id: ObjectId

    @Persevered var short_description: String = ""
    @Persevered var long_description: String = ""
    @Persevered var created_by: String = ""
    @Persevered var created_by_email: String? = ""
    @Persevered var created_date: Date = Date()
    @Persevered var event_type: EventType?
}
class EventType: Object, ObjectKeyIdentifiable {
    @Persevered(primaryKey: true) var _id: ObjectId
    
    @Persevered var title: String
    @Persevered var type_description: String

}

In making an attempt to create a brand new Occasion, the Picker presents nice, with values for every entry within the assortment, nonetheless, it will not let me choose any of the EventTypes.

struct CreateEventView: View {
    @ObservedResults(Occasion.self) var occasions
    @ObservedResults(EventType.self) var eventTypes

    @State non-public var newEvent = Occasion()
    @Binding var isInCreateEventView: Bool
    @State var person: Consumer
    @State var short_description = ""
    @State var long_description = ""
    @State var selected_event_type: ObjectId?

    var physique: some View {
        Kind {
            Part(header: Textual content("New Occasion Particulars")) {
                TextField("Quick Description", textual content: $short_description)
                Picker("Occasion Kind", choice: $selected_event_type) {
                    Textual content("Choose Occasion Kind").tag(ObjectId?.none)
                    ForEach(eventTypes) { eventType in
                        Textual content(eventType.title).tag(eventType._id)
                    }
                }
                Textual content("Chosen Occasion Kind: (selected_event_type != nil ? String(describing: selected_event_type!) : "No Chosen Occasion Kind")")
                TextField("Lengthy Description", textual content: $long_description)
            }
            Part {
                Button(motion: {
                    newEvent.created_by = person.id
                    newEvent.created_by_email = person.profile.e-mail
                    newEvent.short_description = short_description
                    newEvent.event_type = eventTypes.first(the place: { $0._id == selected_event_type })
                    newEvent.long_description = long_description
                    newEvent.created_date = Date()
                    $occasions.append(newEvent)
                    isInCreateEventView = false
                }) {
                    HStack {
                        Spacer()
                        Textual content("Save")
                        Spacer()
                    }
                }
                Button(motion: {
                    print(eventTypes)
                    isInCreateEventView = false
                }) {
                    HStack {
                        Spacer()
                        Textual content("Cancel")
                        Spacer()
                    }
                }
            }
        }
        .navigationBarTitle("Add Occasion")
    }
}

I have been banging my head on this one for days, and might’t get issues to perform correctly. Any assist could be enormously appreciated. The Picker presents values nice, however once I click on on any of the values that pop up, it simply goes again to the default “none” choice.