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
-1
votes
1 answer

Trying to keep a list up-to-date in a SwiftUI app

I am having some issues using SwiftUI whith CoreData. My app has a list of items coming from a core-data entity. The initial (template) code -provided by Xcode when starting a project- works. But problems come when I want to set a predicate in order…
Michel
  • 10,303
  • 17
  • 82
  • 179
-1
votes
1 answer

Fetching multiple objectIDs in Core Data?

After fetching Core Data objects, I need to re-fetch the same set of objects later. I know all IDs, but objects could be changed, so need to fetch again by objectID, all at once. How to achieve that? PS: I cannot just use same predicate as first…
bodich
  • 1,708
  • 12
  • 31
-1
votes
1 answer

Swift: Difference between NSFetchRequest and NSFetchResultsController?

I have a hard time to understand the difference between the NSFetchRequest and the NSFetchResultsController. I also don't know in which situation I would choose which one of them. I would be really happy, if someone could explain it in simple…
user11659384
-1
votes
1 answer

iOS: Problem with the NSManagedObjectContext / NSFetchRequest / NSEntityDescription

I have an error message ' Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[__NSArrayM insertObject:atIndex:]: object cannot be nil' The problem is on the fetchedObjects. This is because it tries to add a value…
-1
votes
2 answers

How to set the relationship between the core data entities?

So, I have a core data database with multiple relationship already populated with data. My problem is that I created the relationships between the tables but i don't know how to set them in code. I only need to set one and then I can figure it out…
Mastertrap
  • 59
  • 1
  • 11
-1
votes
3 answers

How to prevent fatal error: unexpectedly found nil wile unwrapping an Optional value

So I'm new to core data, starting doing some tutorials and got a very basic setup where a 10 scores are saved from the AppDelegate and that works fine (am able to fetch and print from the console). Then when I want to use a fetchrequest in another…
ThirtyKnots
  • 63
  • 1
  • 1
  • 6
-1
votes
1 answer

Error handling on fetch request and NSpredicate

I am extracting data from the past week using CoreData. It all works fine for days when some data is stored. However, when no data is stored, the program crashes. How can I handle this error? for i in 0...6 { // Get every day in the past week …
Nils
  • 313
  • 1
  • 2
  • 14
-1
votes
1 answer

MagicalRecord - how to clear nsfetchedresultscontroller cache and change predicate

The following works one time: self.fetchedResultsController = [Cat MR_fetchAllSortedBy:@"age" ascending:YES withPredicate:predicate groupBy:@"age" delegate:self inContext:[NSManagedObjectContext MR_defaultContext]]; But setting a new predicate and…
soleil
  • 12,133
  • 33
  • 112
  • 183
-1
votes
1 answer

xcode 6: font size changing when scrolling dynamic tables out of range

The font size for textViews in viewControllers which use dynamic tables changes when the row scrolls out of view. This does not happen with static tables. The font size is set correctly in the storyboard. Do I have to explicitly change the font size…
PatriciaW
  • 893
  • 1
  • 12
  • 30
-1
votes
1 answer

CoreData Fetch (Sort by Date) - Doesn't update for new data?

I have a program which has CoreData entities including a NSDate field that indicates date each object was saved. I want to make sure that the user hasn't executed the "saving" code within X minutes (in testing set to 1). If it is within X minutes,…
Charlie
  • 1,279
  • 2
  • 12
  • 28
-1
votes
1 answer

Core data fetch relational object

Im very newbie to iOS programming. I have core data app for tasks with two entities: Group and Task. User creates task groups like Work, Home, Shoping and tasks related to these groups like for Work-Deploy an app, for Shopping-buy milk etc. I…
-1
votes
1 answer

Core Data: Relationships and User Objects

I'm using StackMob with CoreData (remote Database), but I think this is a general Core Data question. I have 3 entities: User (login) Cars Bikes Each entity has several attributes. A User can have multiple Cars and Bikes objects (to-many…
-1
votes
1 answer

Core Data: Fetch

I have a 5 screens. Each screen has options the user choses i.e. via Time & Date picker, and some UIFields that the user will type in. So I created ONE Entity and added all the attributes (25). I created a NSObjectSubClass called LM In each scene…
-1
votes
2 answers

How to check if something is stored in CoreData

Hi I want to be able to tore some information in core data and but i am unsure of how to check if the file was saved properly. I tried using NSLog but it returns null when its called. I have a dictionary which has a uniqueID and a title which I want…
Terrel Gibson
  • 481
  • 1
  • 6
  • 21
-1
votes
1 answer

NSPredicate for nested sets

Say we have A <-->> B <-->> C. We have multiple A entities, and C entities have an attribute called label. How can I find all A entities that contain C entities that contain @"1234"? I saw this SUBQUERY in core data and it works great, but I'm…
zumzum
  • 17,984
  • 26
  • 111
  • 172
1 2 3
74
75