nspredicate

Display data from NSArray in NSTableView

Hi all, I have a problem, and I reckon there's a really straightforward solution to it, but I can't fathom it out! I have this piece of code: NSManagedObjectContext * context = [[NSApp delegate] managedObjectContext]; NSManagedObjectModel * model = [[NSApp delegate] managedObjectModel]; NSDictionary * entities ...

KVC select by criteria

I have a array of objects that selected from core data. I need select from this set subset of object that correspond to condition. How to do it? ...

Can you specify "select unique name from ..." with NSPredicate?

I've got some data stored in Core Data that looks something like: | name | identifier | other_stuff | I need to display the names in a UITableView, but I only want to display the names with unique name-identifier pairs. So for: John | 3 | foo Betty | 4 | foo Betty | 4 | bar I only want the query to return John, Betty. Something li...

CoreData Fetch Request with Most recent Predicate

I have an Entity 'Event' which contains a NSDate 'AccidentDate'. I am trying to do a fetch request to grab only the most recent 'AccidentDate' but I am not sure how to set up the predicate to grab only the last 'AccidentDate' Below is my code so far... NSFetchRequest *fetchRequest1 = [[NSFetchRequest alloc] init]; NSEntityDescription...

NSPredicate: filtering objects by day of NSDate property

I have a Core Data model with an NSDate property. I want to filter the database by day. I assume the solution will involve an NSPredicate, but I'm not sure how to put it all together. I know how to compare the day of two NSDates using NSDateComponents and NSCalendar, but how do I filter it with an NSPredicate? Perhaps I need to create ...

Simple fetch with .@count predicate taking a long time (~30seconds)

I have 2 entities, A and B that have a many to many relationship. The A entity has about 10,000 objects in, and B has about 20 objects. Basically, A objects can be related to one or more B objects, and the B objects keep track of which A objects they are connected to. This is done with the inverse relationship setting. I simply wish t...

What's better way to build NSPredicate with to-many deep relationships?

Hello, I have three entities: EntityA, EntityB and EntityC connected with to-many relationships. See schema for details: For getting all instance of EntityA which depend from EntityB.name I use the predicate like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY EntityB.name like 'SomeName'"]; What should be ...

Case insensitive NSPredicate for strings from an array?

I have a situation where I want to fetch objects from my core data store by the username key, but I want the comparison to be case-insensitive. The predicate I have is this: username IN $usernames I then do a variable substitution with an array of strings that are the usernames I want to find. It works but is case-sensitive. I'd like ...

Using NSPredicate with Core Data for deep relationships

I have an NSArrayController, companiesController bound to a top level Core Data entity, Companies. A Company has many Department's, and a Department has many Employee; these are represented by the 1-to-many relationships, departments and employees. Based on the attribute salary of an Employee I thought I could dynamica...

UISearchBar's TableView doesn't seem to update correctly...

I'm having a problem with using UISearchBar in a UITableView application, where the list is not refreshing itself correctly and the item that is at the index "0" remains the same. Here is some images to demonstrate what is happening: In the first image, I have begun to search a list of names, and the two that show up beginning with 'a' ...

NSPredicateEditor, ignore rows with no search terms?

I'll say right off I am an inexperienced Cocoa programmer, and I apologize if my question is answered in the docs somehow and I merely missed it, or there was something I don't understand in how the NSPredicateEditor works. However, I did attempt to search in the docs and googled, to little effect. Thus, I bring the question to you. I a...

cocoa iphone core-data predicate one-to-many fetchrequest

I have a set of data where one of the attributes (Firmware) is a one-to-many relationship. If I want to get any records where the firmware id is 1 I can create a predicate using @"(ANY Firmware.FID==1)" Then I have another set of conditions that will refine the set even more using (TopLevel==YES) AND (Parent>0) How can I combine t...

Using NSPredicate with Core Data NSFetchedResultsController

I have a fetchedResultsController that has returned all records for my entity "Account". I would like to quickly search all Account records for the attribute "lastName" == value, and give me back the Account object, or at least the indexPath of the object in the fetchedResultsController. There should only be 1 object returned. Other th...

NSDate constant for Fetch Predicate

I'm using the Fetch Predicate in the IB to filter our the default result return from Core Data and I'm actually looking for some like this: dateCreated < YESTERDAY where "YESTERDAY" is supposed to be a nsdate constant for yesterday so that all my result return is before yesterday. This didn't work. And some searching didn't turn up a...

NSFetchedResultController and UISearchBar implementation

Hey! I'm creating a simple Navigation-based app using core data for my iPhone and I'm trying to implement a little search. The app is baed on the "Navigation-based application"-template from Apple. The NSFetchedResultsController gets all the objects and they will be displayed in the table view. I've also have left the Plus button to add...

Objective-C: NSPredicate LIKE doesn't like spaces. Is there an escape sequence to replace blanks with?

I have a NSPredicate that looks like this: NSPredicate *likePredicate3= [NSPredicate predicateWithFormat:@"synonyms LIKE[cd] %@",[NSString stringWithFormat:@"%@", searchText]]; I apply it to an NSArray of objects of a class that has the 'synonyms' property. It works fine when the searchText is a whole word such as "Thanks". However...

NSPredicate aggregate IN statement not working

I am a bit of a CoreData noob but am slowly getting my head around it. I am having trouble with the following code: NSArray * artisteIds = [@"1,2,3,4" componentsSeparatedByString:@","]; predicate = [NSPredicate predicateWithFormat:@"(artisteId IN %@)", artisteIds]; My Artiste managed object has a NSNumber field of artisteId and I hav...

Using filteredArrayUsingPredicate always returns an empty array for Core Data fetched objects.

I'm trying to use NSArray's filteredArrayUsingPredicate: method to filter an array of core data managed-objects. Here's an outline: NSArray *array = self.fetchedResultsController.fetchedObjects; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchString]; NSArray *filteredA...

How to setup NSPredicate and NSEntityDescription in Coredata to do complicated SQL query

I know how to create NSPredicate to do sql like "SELECT * FROM DRINK". But how about this query: "SELECT I.name, D_I.amount FROM DRINK_INGREDIENT D_I, DRINK, INGREDIENT I WHERE D_I.drinkID=1 AND DRINK.drinkID=1 AND I.ingredientID = D_I.ingredientID;" How do I even set the NSEntityDescription, and NSPredicate for this kind of que...

How to make an NSFetchRequest which asks for objects that have a specific firstname?

For example, I have a Managed Object Model with an Entity called "Friends", and a friend has a firstName. I want to get all friends where the firstName is equal to "George". How can I do that? ...