Relative Content

Tag Archive for swiftuiswiftdata

Display a list of objects from SwiftData with a Toggle and no bool in the object

I would like to display a list of objects queried from SwiftData, each objects having a Toggle. I obviously need a bool for each object for the state of the toggle. The usual way of doing things is to put a isChecked member in the Student object, but I can’t (the actual code is worse as I don’t have only two courses, maths and physics, but a list of courses coming from a query from the database). Of course, a student can appear in many different courses, so I can’t even have one isChecked in the Student object that could work for all the courses.

Grouping Results by date in SwiftData using SwiftUI

Note:a visually different project class EventModel { var eventName: String var eventDate: Date var backgroundColor: String var iconName: String var notification: Bool } @Environment(.modelContext) var context @Query(sort: EventModel.eventDate) private var events: [EventModel] List { ForEach(events) { index in EventView(state: model.makeEventCellViewState(event: index)) .onTapGesture { model.eventToEdit = index } } .onDelete { indexSet in for index in […]

How do I import CSV into SwiftData? Current code is not working

I am trying to code a SwiftUI app in iOS which will utilize SwiftData and import the data from a CSV file within the app package. However, it is not loading the data. As you can see below, the view is using a list and foreach to go through the entries in the class/array of Shop. The CSV file has two ‘shops’ in it, yet none show on the view. Any help is appreciated!