Sharing a ModelContainer Instance Between App and WidgetBundle Targets in swiftui
I am encountering an issue when attempting to share the same ModelContainer
instance between two separate targets: App
and WidgetBundle
. To achieve this, I created a StorageController
to manage the ModelContainer
and injected it into both targets.
SwiftUI – ForEach model class variable
I’m attempting to build a todo app using SwiftUI + Swift Data. I’ve created a model like this:
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.
Description-field in a @Model
I have a @Model
class like so:
How to manually listen for updates to a SwiftData @Model object?
Let’s say I have a class like this:
How to get total records in SwiftData so can display the proper records or ContentUnavailableView (Custom or .search)
Watched Paul Hudson long SwiftData Tutorial and wanted to modify it by putting in the built-in ContentUnavailableView.search
“No Search Results” view and also a custom “ContentUnavailableView” when there are no physical records/objects in SwiftData Person class to start. This custom View has an “add” button.
How to setup if-else in SwiftUI Views so can display the proper ContentUnavailableView (Custom or .search)
Was watching Paul Hudson – Hacking with Swift 2 hour plus video that he did in December on birthday and followed everything fine. I have an OK understanding of SwiftUI but learning. The ContentView drives the creation and searching of People. PeopleView let us refactor most of the body so that we could change the searching / sorting dynamically.
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!
Using SwiftData and getting a Nil value for a very odd reason which I can’t understand why
I am trying to learn SwiftData, so I created a very simple app (macOS) to learn the basics. I ran into what turns out to be very odd behavior (at least I am not understanding).