1

I want to load more cells when user in the last cell. I use CoreData and I get data from it. I use this answer to do what I want, but it didn't work. What problem can be there? Also I have one more question. I don't know why working only first implementation.

First implementation

var fetchedResultsController: NSFetchedResultsController {
    let moc = DatabaseController.sharedInstance.managedObjectContext
    let fetchRequest = NSFetchRequest()
    let entity = NSEntityDescription.entityForName("Coctail", inManagedObjectContext: moc)

    fetchRequest.entity = entity
    fetchRequest.fetchLimit = 10
    fetchRequest.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]

    let aFetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest,
                                                               managedObjectContext: moc,
                                                               sectionNameKeyPath: nil,
                                                               cacheName: nil)
    aFetchedResultsController.delegate = self

    do {
        try aFetchedResultsController.performFetch()
    } catch {
        fatalError("\(error)")
    }
    return aFetchedResultsController
}

Second Implementation

func initilizeFetchedResultsController() {
    let moc = DatabaseController.sharedInstance.managedObjectContext
    let fetchRequest = NSFetchRequest()
    let entity = NSEntityDescription.entityForName("Coctail", inManagedObjectContext: moc)

    fetchRequest.entity = entity
    fetchRequest.fetchLimit = 10
    fetchRequest.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]

    let aFetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest,
                                                               managedObjectContext: moc,
                                                               sectionNameKeyPath: nil,
                                                               cacheName: nil)
    aFetchedResultsController.delegate = self

    do {
        try aFetchedResultsController.performFetch()
    } catch {
        fatalError("\(error)")
    }
    fetchedResultsController = aFetchedResultsController
}
Community
  • 1
  • 1
cmashinho
  • 605
  • 5
  • 21

1 Answers1

1

Hard to tell why the first solution but the second doesn't without seeing the other code that would have used the fetchedResultsController or called initilizeFetchedResultsController().

The reason you're not getting more data is that you've hardcoded your fetchLimit to 10. No matter what you do, you'll only ever get 10 results.

You'll need to change the fetchLimit to get more data. Check out this answer -- it is similar to what you'll need to do: https://stackoverflow.com/a/6786931/5605379

Community
  • 1
  • 1
  • I do it like in this [answer](http://stackoverflow.com/questions/20269474/uitableview-load-more-when-scrolling-to-bottom-like-facebook-application/22732057#22732057) and I chanced fetchLimit – cmashinho Jun 17 '16 at 09:17