0

I want to get the number of items that I will get if a fetch request is executed. I use the countFor of the NSManagedObject. For count and offset, there are non-negative values and also count is greater than 0. When the code is executed, app crashes with this in console.

[error] error: SQLCore dispatchRequest: exception handling request: <NSSQLCountRequestContext: 0x600002990c40> , Invalid SQL (must specify a limit with an offset) with userInfo of (null) CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLCountRequestContext: 0x600002990c40> , Invalid SQL (must specify a limit with an offset) with userInfo of (null) 2022-01-05 18:16:43.413899+0530 colegia[11406:83454] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid SQL (must specify a limit with an offset)'

Code:

 context.performAndWait {

        let request: NSFetchRequest = NSFetchRequest<NSManagedObject>.init(entityName: "ENTITY_NAME")

        
        request.fetchLimit = count
        
        request.fetchOffset = offset
           
        request.includesPropertyValues = false
                                
        do {
            announcementsCount = try context.count(for: request)
        }catch let error as NSError {
            print("Could not fetch. \(error), \(error.userInfo)")
        }
 }

What am I missing here ?

Akilan C B
  • 199
  • 1
  • 9

0 Answers0