Fetch limit ? #95

Closed
opened 2025-12-29 15:24:32 +01:00 by adam · 3 comments
Owner

Originally created by @ThibaultVlacich on GitHub (Oct 25, 2016).

Hello,

When doing a CoreStore.fetchAll request, I haven't found a way to put a limit to number of entries to fetch. Is there a way to do that ? Something like :

CoreStore.fetchAll(
    From(Article.self),
    Where("featured = 1"),
    OrderBy(.descending("date")),
    Limit(10)
)

With CoreData alone I was doing (Swift 2) :

let request = NSFetchRequest(entityName: "Articles")
request.fetchLimit = 10
Originally created by @ThibaultVlacich on GitHub (Oct 25, 2016). Hello, When doing a `CoreStore.fetchAll` request, I haven't found a way to put a limit to number of entries to fetch. Is there a way to do that ? Something like : ``` swift CoreStore.fetchAll( From(Article.self), Where("featured = 1"), OrderBy(.descending("date")), Limit(10) ) ``` With CoreData alone I was doing (Swift 2) : ``` swift let request = NSFetchRequest(entityName: "Articles") request.fetchLimit = 10 ```
adam closed this issue 2025-12-29 15:24:32 +01:00
Author
Owner

@JoeMatt commented on GitHub (Oct 25, 2016):

You would use Tweak parameter to modify the NSFetchRequest directly.

CoreStore.fetchAll(
    From(Article.self),
    Where("featured = 1"),
    OrderBy(.descending("date")),
    Tweak { (fetchRequest) -> Void in
         fetchRequest.fetchLimit = 10
    }
)
@JoeMatt commented on GitHub (Oct 25, 2016): You would use Tweak parameter to modify the NSFetchRequest directly. ``` swift CoreStore.fetchAll( From(Article.self), Where("featured = 1"), OrderBy(.descending("date")), Tweak { (fetchRequest) -> Void in fetchRequest.fetchLimit = 10 } ) ```
Author
Owner

@ThibaultVlacich commented on GitHub (Oct 25, 2016):

Thanks @JoeMatt! I'm gonna take a look if maybe I can make a PR to add a convenient Limit fetch clause.

@ThibaultVlacich commented on GitHub (Oct 25, 2016): Thanks @JoeMatt! I'm gonna take a look if maybe I can make a PR to add a convenient `Limit` fetch clause.
Author
Owner

@JakeSteam commented on GitHub (Nov 4, 2017):

Semi-resurrecting this, any chance it can be put into the readme? Having to search through closed issues to find out how to limit seems crazy!

@JakeSteam commented on GitHub (Nov 4, 2017): Semi-resurrecting this, any chance it can be put into the readme? Having to search through closed issues to find out how to limit seems crazy!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#95