fetchedresults

    SwiftUI + CoreData FetchRequest Predicate 사용법

    swiftUI 기반 환경에서 CoreData를 사용시 데이터를 필터하여 보여주어야 할 때가 있다. 차근차근 알아보자 데이터 불러오기 먼저 FoodEntity라는 데이터를 사용한다고 가정해보자. 다음과 같이 CoreData로 부터 데이터를 불러올 것이다. @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \FoodEntity.timestamp, ascending: true)], animation: .default ) private var foods: FetchedResults 필터 적용하기 여기에 predicate인자를 통해 필터를 적용할수 있다 @State var filterKey = "한식" @FetchRequest( sortDescriptors:..