I was looking for an example for a DataStore in SwiftUI and found this example.
import SwiftUI
import Combine
class MyDatabase: ObservableObject {
let didChange = PassthroughSubject<MyDatabase, Never>()
var contacts: [Contact] = [
Contact(id: 1, name: "Anna"), Contact(id: 2, name: "Beto"),
Contact(id: 3, name: "Jack"), Contact(id: 4, name: "Sam")
] {
didSet {
didChange.send(self)
}
}
struct Contact: Identifiable{
var id: Int
var name: String
}
}
struct ContactsList: View {
@EnvironmentObject private var database: MyDatabase
var body: some View {
NavigationView {
List($database.contacts) { contact in
NavigationLink(destination: ContactDetail(contact: contact)) {
Text(verbatim: contact.value.name)
//here Error 1: Types of expression....
}
}
.navigationBarTitle(Text("Contacts"))
}
}
}
struct ContactDetail: View {
@Binding var contact: MyDatabase.Contact
var body: some View {
VStack {
TextField($contact[\.name])
.textFieldStyle(.roundedBorder)
.font(.title)
.padding()
//here Error 2: Types of expression....
Spacer()
}
.navigationBarTitle(Text("Edit"), displayMode: .inline)
}
}
However, after testing it, I got the below error multiple times:
Type of expression is ambiguous without more context
I also tried following tutorial for the same solution https://mecid.github.io/2019/07/03/managing-data-flow-in-swiftui/ but I got the same errors. Did anything changes regarding the Bindings in the latest beta? Im running Beta 6