I have a SwiftUI view that is being passed a binding from a parent view. I would like to preview the subview, but can't. I tried .constant and a @Model object directly. Both ways crash the preview.
Any idea on how I can get this to work properly?
@Model
class FamilyMember: Identifiable {
@Attribute(.unique) var id: String { name }
var name = ""
init(name: String = "") {
self.name = name
}
}
struct MemberView: View {
@Bindable var member: FamilyMember
var body: some View {
Text(member.name)
}
}
#Preview {
MemberView(member: FamilyMember(name: "Family member"))
}
#Preview {
MemberView(member: .constant(FamilyMember(name: "Family member")))
}