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

App becomes unresponsive on NSFetchRequests

I have the above CoreData Model in my first iPad app. I'm building a filtering system in a TableViewController as shown below. The problem is that whenever I make a UI change, toggle a switch of tap a button, My UI becomes non-responsive for a…
0
votes
1 answer

What is the correct way for quering a NSNumber in a NSArray within CoreData?

I have a Entity with a column of type ID named "responsibleUsers". In this column I store an Array containing NSNumbers. I want to fetch all objects of this entity, that match my current User. Therefore i create following predicate: [NSPredicate…
Dominic Sander
  • 2,714
  • 1
  • 18
  • 29
0
votes
2 answers

CoreData: findAll returns objects, but simple fetchRequest does return 0 objects

I am using CoreData and executing the following command returns a number of objects: [Contact findAll]; However when I setup a simple NSFetchrequest like so, I get 0 objects. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; …
Besi
  • 22,579
  • 24
  • 131
  • 223
0
votes
2 answers

Fast access to Core Data database information?

i have iOS application with core data, in one of my function i load the information to display one view of my application in this way: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription …
Piero
  • 9,173
  • 18
  • 90
  • 160
0
votes
1 answer

NSFetchRequest canot fetch entity present in context

I have a problem where I am inserting entities A in a context. Right after I insert all of the entities A I execute a fetch request on the context: NSEntityDescription* entity = [NSEntityDescription entityForName:@"A"…
zumzum
  • 17,984
  • 26
  • 111
  • 172
0
votes
2 answers

Core Data - Sort descriptor for parent / child hierarchy

I get a JSON object from a HTML request which contains a hierarchical structure. Sample from JSON object: { "_id": "4f870f064f95ae0da8000002", "name": "Category", "parent_id": null }, { "_id": "4f870f0e4f95ae0da8000004", "name":…
0
votes
2 answers

How to access CoreData entities based on a to-many relationship of another entity?

I am learning CoreData with a sample inventory app. My Data Model has 2 entities, "Possession" and "Asset Type". Possessions have a to-one relationship to Asset Types called "assetType" and Asset Types have a to-many relationship to Possessions…
vichudson1
  • 881
  • 1
  • 10
  • 21
0
votes
1 answer

How to sum up a fetched result's number property based on the object's category?

I have a NSFetchRequest that is returning all my saved objects (call them Items) and storing them in an NSMutableArray. Each of these Items have a category, an amount, and some other properties. My goal is to check the category of each Item and…
0
votes
1 answer

Does NSSet *children = [parent children]; perform a fetch request?

Is NSSet *children = [parent children]; causing core data to perform a fetch, returning all instances of the child entity relationship? Same in IB: Does a Model Key Path with a nested relationship perform a fetch request?
bijan
  • 1,675
  • 18
  • 30
-1
votes
1 answer

How to only fetch Objects already saved to Context and ignore Temporary Objects in CoreData and Swift?

Context I am building an app that uses CoreData. When opening a NewEntityForm, the app creates an Object of this Entity for the User to manipulate. When the User saves his changes, it gets saved to Context, otherwise it gets discarded using…
christophriepe
  • 1,157
  • 12
  • 47
-1
votes
1 answer

Core Data NSFetchRequest returns empty objects

I am facing an issue with an NSFetchRequest returning object with "empty" properties, even though it is correctly retrieved from database and returnsObjectsAsFaults is set to false. // Object @objc(Task) final class Task: NSManagedObject { …
Yonic Surny
  • 451
  • 6
  • 15
-1
votes
1 answer

How can I fetch value from CoreData to Variable?

CoreData: Item userName userSurname Fetch request @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)], animation: .default) private var items: FetchedResults How can I apply last…
Kirill
  • 11
  • 4
-1
votes
1 answer

while using 'fetch()', i got the answer, "failed to feth"

I would like to ask question related to fetching. I'm required to create a weather website. For this, firstly, I registered in weather api, got a key, and formulated my 'url' by following api doc. Now, the url itself seems…
-1
votes
1 answer

SwiftUI: How to change @EnvironmentObject in runtime? / How to pass different NSManagedObjectContext in runtime?

I have a SwiftUI app using Core Data and CloudKit with the NSPersistentCloudKitContainer. I pass the NSManagedObjectContext to my views with an environment variable like so: WindowGroup { HomePage() .environment(\.managedObjectContext,…
-1
votes
3 answers

@FetchRequest predicate is ignored if the context changes

I have a simple SwiftUI application with CoreData and two views. One view displays all "Place" objects. You can create new places and you can show the details for the place. Inside the second view you can add "PlaceItem"s to a place. The problem is…
Tobias Tom
  • 43
  • 5