I've got
@Environment(\.managedObjectContext) var context
private var home: Home
private var predicate: NSPredicate
@State var sortBy: SortDescriptor<Room>
@FetchRequest private var rooms: FetchedResults<Room>
init(home: Home) {
self.home = home
_sortBy = State(initialValue: SortDescriptor<Room>(\.name))
self.predicate = NSPredicate(format: "%K = %@", "home", self.home)
_rooms = FetchRequest<Room>( sortDescriptors: [self.sortBy], predicate: self.predicate)
}
But it won't compile -- it says Variable 'self.rooms' used before being initialized
. But... how?