Questions tagged [nsfetchrequest]

On macOS 10.4+ and iOS 3.0+, an instance of NSFetchRequest describes the search criteria used to retrieve data from a persistent store. It is a class in the Apple Core Data Framework.

From the NSFetchRequest documentation:

An instance of NSFetchRequest collects the criteria needed to select and optionally to sort a group of managed objects held in a persistent store. (See NSPersistentStore and NSManagedObject.) A fetch request must contain an entity description (an instance of NSEntityDescription) or an entity name that specifies which entity to search. It frequently also contains

  • A predicate (an instance of NSPredicate) that specifies which properties to filter by and the constraints on selection, for example, “last name begins with a ‘J’”. If you don’t specify a predicate, then all instances of the specified entity are selected (subject to other constraints; see executeFetchRequest:error: for full details).

  • An array of sort descriptors (instances of NSSortDescriptor) that specify how the returned objects should be ordered, for example, by last name then by first name.

Questions related to this can also be tagged with .

NSFetchRequest objects can be used with the method executeFetchRequest:error:, defined by NSManagedObjectContext.

Sample syntax:

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Employee"
                inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
1115 questions
0
votes
1 answer

How to get a sum for a particular attribute in a CoreData DB?

I recently have just been able to populate my core data DB. I have an attribute named username and I would like to get the total number of users on the system (in the DB) and print it out. I know I need to use NSFetchRequest along with…
ipatch
  • 3,933
  • 8
  • 60
  • 99
0
votes
1 answer

Core Data: filtering entries based on time component of NSDate

I have an entity with an attribute time, which is of type Date. I only care about the time component of it. When generating the class files, I chose to use scalar properties for primitive data types. So, NSTimeInterval is used instead of NSDate. To…
William Niu
  • 15,798
  • 7
  • 53
  • 93
0
votes
1 answer

How to debug NSFetchRequest

I am using Core Data on iOS and am having problems with NSFetchRequest. If I create an NSFetchRequest like so: NSFetchRequest* request = [ NSFetchRequest fetchRequestWithEntityName:@"Recipe"]; and then create instances of my Recipe entity, they…
deltanine
  • 1,166
  • 1
  • 13
  • 25
0
votes
1 answer

NSFetchedResultsControllerDelegate

Hi I am a trying to use a custom delegate alongside the NSFetchedResultsController delegate but I am finding if I implement my XMLParserDelegate the the fetch results controller does not populate the UITableview but if I remove the XMLParserDelegate…
0
votes
3 answers

iPhone Core Data NSFetchRequest

I'm not new to this technology, but one thing is bugging me out. It's about Core Data. Let's assume I have db model like this: Person <-> House <-> House details <-> means two-way relationship and Person has many houses, each house has it's details…
ypso
  • 5
  • 2
0
votes
1 answer

for loop through fetchedResultsController

I need to loop through a fetchedResultsController but having some issues. Here is the code; for (NSFetchedResultsController *singleResult in _fetchedResultsController) { //For logic } The warning is; Collection expression type…
Xaphann
  • 3,195
  • 10
  • 42
  • 70
0
votes
1 answer

UITableView Sections based on Core Data attribute

In my app, I have a UITableView that is populated by Core Data, currently a string called "name." I want to be able to divide this tableview into 3 sections, which could be named 0, 1 and 2, or 1, 2 and 3. The name doesn't really matter. I currently…
mhbdr
  • 753
  • 2
  • 10
  • 26
0
votes
1 answer

NSFetchRequest, possible to filter by aggregate functions?

I am trying to pull all the Actions which belong to the latest Session. In SQL this would be a simple JOIN ... WHERE Session.startTime = MAX(Session.startTime), but with Core Data I can't figure out how to do this without resorting to two steps as…
0
votes
1 answer

CoreData: Fetch an object that has a given property AND a given relationship?

I have a CoreData model that looks a bit like this: Object A: Results -- A one to many relationship to an indeterminate number of Object B's. Object B: Object Name -- A string. (potentially not unique) Parent -- A singular relationship with…
radven
  • 2,296
  • 1
  • 22
  • 39
0
votes
1 answer

NSFetchedResultsController add Objects manually

I recently stumbled across a difficult problem.. I'm normally using a NSFetchedResultsController to get Data out of my CoreData, and display it within a TableViewController. The problem I have now is that I can't get the results I want with a…
dominik
  • 1,319
  • 13
  • 23
0
votes
1 answer

NSFetchedResultsController trying to limit number of records displayed

When creating a NSFetchRequest to pass over to my NSFetchedResultsController I am setting the fetchLimit property to 3. Now initially this appears to work fine. I can modify the first three returned objects in any way which changes their order and…
trapper
  • 11,716
  • 7
  • 38
  • 82
0
votes
3 answers

NSFetchRequest to show results in particular order

Suppose I have one entity 'Person' in core data. Now i want to search all persons. Either firstname beginning match or lastname beginning match. For eg : 1) Amit Gupta 2) Ajay Gulati 3) Gunjan Aggarwal Searching for 'Gu' shows names that match…
0
votes
1 answer

NSFetchRequest release causes app to crash

The static analyzer keeps telling me that I have a +1 retain count for my request object and instruments tells me there is a leak there. However, no matter where I try to release it, it keeps crashing my app. It's the same with NSPredicate object.…
NSCoder
  • 1,594
  • 5
  • 25
  • 47
0
votes
2 answers

Core Data attribute count and show the result in a TableView

I've got an entity called Car with 2 attributes: name and color. I have several cars in the database: name: Honda Civic color: Blue name: VW Golf color: Blue name: Renault Twingo color: Red name: Chevrolet Camaro color: White Now I need to count…
Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
0
votes
2 answers

Bizarre Core Data behavior when fetching unsaved data

I have a Core Data importer that loops through data, and ignores duplicate records during the import process. But I have discovered that my NSFetchRequest is not matching against recently stored records that have not been saved. And I am seeing…
radven
  • 2,296
  • 1
  • 22
  • 39