对CoreData制作FetchedResults
时,如何限制检索到的FetchRequest
的大小?
struct ContentView: View {
var fetchRequest:FetchRequest<Kana>
init(){
fetchRequest = FetchRequest<Kana>(entity: Kana.entity(), sortDescriptors: [], predicate: NSPredicate(format: "alphabet == %@", "hiragana"))
}
var body: some View {
List{
Text("10 Kanas")
// Display 10 Kanas
}
}
}
答案 0 :(得分:2)
您需要使用相应的初始化程序使用FetchRequest
创建NSFeatchRequest
,如下所示
init() {
let request: NSFetchRequest<Kana> = Kana.fetchRequest()
request.fetchLimit = 10
request.predicate = NSPredicate(format: "alphabet == %@", "hiragana")
fetchRequest = FetchRequest<Kana>(fetchRequest: request)
}