Hello, I'm a little confused as to how to use my attributes that are in an entity in CoreData in a SwiftUI View. In this case, I have an entity called "Meeting", and it has string attributes called "meetingName" and "meetingLink". I have set up a persistence controller and everything seems to work fine, but I've run into an issue where I want to display the meetingName attributes in a list. I'm doing this by creating a view called MeetingRow, then using the following HStack:
It tells me that I don't have member meetingName in the fetched results, which is why I'm confused. Thank you in advance for your help!
Code Block struct MeetingRow: View { @Environment(\.managedObjectContext) var managedObjectContext @FetchRequest( entity: Meeting.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: \Meeting.meetingName, ascending: true), NSSortDescriptor(keyPath: \Meeting.meetingLink, ascending: false) ] ) var meetings: FetchedResults<Meeting> var body: some View { HStack { Spacer() .frame(width: 20) Text(meetings.meetingName ?? "nil") } /* This ^^ is the offending line (error: Value of type 'FetchedResults<Meeting>' has no member 'meetingName' */ Spacer() } }
It tells me that I don't have member meetingName in the fetched results, which is why I'm confused. Thank you in advance for your help!
If you removed the meetings property, that error message is stale.
You may need to supply a Meeting object to the preview. One of the following two methods should work:
First, supply an empty Meeting object.
Second, use the .constant modifier when supplying the Meeting object.
You may need to supply a meeting name, URL, and date to the initializer.
You can also temporarily comment out the preview code to get the app to build.
You may need to supply a Meeting object to the preview. One of the following two methods should work:
First, supply an empty Meeting object.
Code Block MeetingRow(meeting: Meeting())
Second, use the .constant modifier when supplying the Meeting object.
Code Block MeetingRow(meeting: .constant(Meeting()))
You may need to supply a meeting name, URL, and date to the initializer.
You can also temporarily comment out the preview code to get the app to build.