nspredicate

Filter Core Data results by property IN array

一曲冷凌霜 提交于 2019-11-30 06:01:38
I currently have Core Data successfully returning all of the results for a specific entity titled Event : NSManagedObjectContext *context = [delegate managedObjectContext]; NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:context]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:entityDescription]; NSError *error; NSArray *fetchResults = [context executeFetchRequest:request error:&error]; One property of the Event entity is a string titled tid . I also have an array filterArray that contains all allowed tid

Reuse NSPredicate for new variable substitute

家住魔仙堡 提交于 2019-11-30 05:37:11
Can I reuse NSPredicate for new variable substitute? My NSPredicate is rather simple: NSPredicate *userPredicate = [NSPredicate predicateWithFormat:@"id == %@",userID]; The userID is generated at run-time with different value, right now for each userID I need to create a NSPredicate. So is it possible I can reuse my NSPredicate ? Yep, you can do this with a variable: NSPredicate *userPredicate = [NSPredicate predicateWithFormat:@"id == $user"]; Save that predicate somewhere, then do this when you need to actually start filtering stuff: NSDictionary *sub = [NSDictionary dictionaryWithObject

NSPredicate subquery syntax

老子叫甜甜 提交于 2019-11-30 05:27:12
I have sort of an unfriendly array of dictionaries that in turn have arrays of data and I am trying to filter the outer array based on any of the inner array passing a predicate. I can't seem to create an NSPredicate to make this work. I started off with: NSPredicate *lookupPredicate = [NSPredicate predicateWithFormat: @"row_values.property_id == %@ AND row_values.property_value == %@", @"47cc67093475061e01000540", @"Male"]; [dataRows filterUsingPredicate:lookupPredicate]; This returns no values. I've tried various forms of ANY but I can't seem to find anything that it will parse. Again, the

How can I use NSPredicate to filter on core data relationships?

心已入冬 提交于 2019-11-30 05:26:43
Say I have core data objects of type "obj" that has a property "propertyA" and a one-to-many relationship with an object of type "sub" that has two properties, "propertyB" and "propertyC". I want to fetch all the objs that have propertyA equal to a value and a sub obj with propertyB and propertyC set. If it was just propertyA and propertyB, I would do [NSPredicate predicateWithFormat:@"ANY sub.propertyB = %@ AND propertyA == %@", ...]; The problem is that I can't figure out how to add in the second property. I want only the objs that have at least one sub that has the two properties true. I've

How to sort NSPredicate

眉间皱痕 提交于 2019-11-30 05:04:38
I am trying to sort my array while using NSPredicate.. I have read other places that possibly using NSSortDescriptor could be an option. Having some trouble figuring this out. I am attempting to sort my array by companyName. Any advice appreciated, thanks Greg - (void)filterSummaries:(NSMutableArray *)all byNameThenBooth:(NSString*) text results:(NSMutableArray *)results { [results removeAllObjects]; if ((nil != text) && (0 < [text length])) { if ((all != nil) && (0 < [all count])) { NSPredicate *predicate = [NSPredicate predicateWithFormat: @"companyName contains[cd] %@ OR boothNumber

NSPredicate and CoreData - decide if a Date attribute is “today” (or between last night 12am to tonight 12am) on iOS

我与影子孤独终老i 提交于 2019-11-30 03:45:45
问题 I'm using a NSFetchedResultsController and a UITableViewController to populate a UITableView from a CoreData database. I have a NSDate object saved into this Date attribute labeled "startTime". Then I'm trying to only pull todays's data by using a NSPredicate that looks like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate == %@", todaysDate]; I'm getting zero results. I understand this because a NSDate object just hold the number of seconds or milliseconds or

Multiple NSPredicate

谁说胖子不能爱 提交于 2019-11-30 01:32:10
问题 I'm trying to prepare multiple search in my CoreData entity Recipes . There are parameters by which I would like to prepare fetch. Recipes attributes: @property (nonatomic, retain) NSNumber * difficulty; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSNumber * code; //like identifier @property (nonatomic, retain) NSNumber * prepTime; Ingredients is a separate entity with the list of ingredients. Join entity contains ingredientCode , recipeCode , count .

Combining Two Conditions in NSPredicate

烂漫一生 提交于 2019-11-30 00:36:38
问题 How do you combine two conditions in NSPredicate ? I am using the following statement and I would like to add another condition that compares the the password with the contents of a textfield using AND : request.predicate = NSPredicate(format: "username = %@", txtUserName.text!) 回答1: Try this request.predicate = NSPredicate(format: "username = %@ AND password = %@", txtUserName.text!, txtPassword.text!) 回答2: As already said, you can use logical operators like "AND", "OR" in predicates.

How to use binary flags in Core Data?

北城以北 提交于 2019-11-30 00:11:30
I have an int32 attribute in a Core Data database. I use this int as an enum bit field. Is it possible to create a NSPredicate to query items based on the binary value of this int ? Something like @"bitFieldAttribute & 0x0001" ? I'm also wondering if this is possible with a binary typed attribute ? NSPredicate can handle it, but I'm not sure if CoreData will accept it as a valid predicate for execution on a data store. It might have trouble converting the bitwise operator into a SQL query (if you're using a SQLite backing store). You'll just have to try it. The syntax, however, is just what

Using NSPredicate with Core Data NSFetchedResultsController

南笙酒味 提交于 2019-11-29 23:53:08
问题 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 than iterate through every objectAtIndexPath, is there a better way to search the fetchController using NSPredicate? 回答1: mootymoots, just filter the fetched