How to limit the number of results in a FetchRequest in SwiftUI

前端 未结 1 1233
甜味超标
甜味超标 2021-01-06 02:31

How can I limit the size of the retrieved FetchedResults when making a FetchRequest to CoreData?



        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 03:11

    You need to create FetchRequest with NSFeatchRequest using corresponding initialiser, as shown below

    init() {
        let request: NSFetchRequest = Kana.fetchRequest()
        request.fetchLimit = 10
        request.predicate = NSPredicate(format: "alphabet == %@", "hiragana")
        fetchRequest = FetchRequest(fetchRequest: request)
    }
    

    0 讨论(0)
提交回复
热议问题