create custom Cell by using core data in swiftUI

170 Views Asked by At

I want to create a custom Cell for my app with swiftUI and i can't put it in textView. I dont want to use ForEach.

In my core data i have 1 entity: FacturationCoreData. In this entity i have 3 attributes: Article, Price, Quantity.

When I use Text(facture.price), I cant find price in attribute in my core data and i have 3 errors:

1.

Initializer 'init(_:)' requires that 'Binding' conform to 'StringProtocol'

Referencing subscript 'subscript(dynamicMember:)' requires wrapper 'Binding<FetchRequest.Configuration>'

Value of type 'FetchedResults' has no dynamic member 'price' using key path from root type 'FetchRequest.Configuration'

4.Insert '$'

struct FactureRow: View {
    
    @Environment(\.managedObjectContext) private var viewContext
    @FetchRequest(entity: FacturationCoreData.entity(), sortDescriptors: []) private var factures: FetchedResults<FacturationCoreData>

    
    var body: some View {
        VStack(alignment: .leading) {

            Text(factures.price)
        
            
        }
    }
}

struct FactureRow_Previews: PreviewProvider {
    static var previews: some View {
        FactureRow().previewLayout(.sizeThatFits)
      
            
    }
}
0

There are 0 best solutions below