I would appreciate help with SwiftUI bindable lists. I read the following article and tried it on my app but I'm getting errors. https://www.swiftbysundell.com/articles/bindable-swiftui-list-elements/
First, the following View including the non-bindable ordinary ForEach list works fine without any errors
@ObservedObject var notificationsViewModel = NotificationsViewModel.shared
//NotificationsViewModel does a API call and puts the fetched data in the Notifications Model
var body: some View {
VStack {
ForEach(notificationsViewModel.notifications?.notificationsDetails ?? [NotificationsDetail]()) { notificationsDetail in
---additional code here--- }
}
Model below:
struct Notifications: Codable, Identifiable {
let id = UUID()
let numberOfNotifications: Int
var notificationsDetails: [NotificationsDetail]
enum CodingKeys: String, CodingKey {
case numberOfNotifications = "number_of_notifications"
case notificationsDetails = "notifications"
}
}
struct NotificationsDetail: Codable, Identifiable, Equatable {
let id: Int
let notificationsCategoriesId: Int
let questionsUsersName: String?
enum CodingKeys: String, CodingKey {
case id = "notifications_id"
case notificationsCategoriesId = "notifications_categories_id"
case questionsUsersName = "questions_users_name"
}
}
When I try to change this ForEach to a bindable one, I start getting multiple errors.
ForEach($notificationsViewModel.notifications?.notificationsDetails ?? [NotificationsDetail]()) { $notificationsDetail in
---additional code here using $notificationsDetail---}
When I try to fix some of the errors such as "remove ?", I get a new error saying I need to add the ?.
When I delete the default value ?? NotificationsDetail, I still get errors

The Xcode build version is iOS15.
Does anyone know how to fix this? Thanks in advance.

